向服务器发送修改后的请求的 Fiddlerscript 将不起作用



我创建了一个小提琴脚本规则,我认为它会等待特定的对象:值,自动将json值的一部分作为具有相同标头信息(如cookie(的post请求发送回不同的URI。

激活脚本后,我收到错误。我认为它与 json 对象值有关。

static function OnBeforeResponse(oSession: Session) {
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "application/json")) {
oSession["ui-backcolor"] = "blue"; 
oSession.utilDecodeResponse();
}
if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "application/json") && oSession.utilFindInResponse("faceId", false) > -1) {
oSession["ui-backcolor"] = "green"; 
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.requestBodyBytes);
var j = Fiddler.WebFormats.JSON.JsonDecode(oBody);
var facId = j.JSONObject["faceId"];
var reqBod = '{"faceId":"' + facId + '"}';
oSession.oRequest.headers.HTTPMethod == "POST";
oSession.utilSetRequestBody(reqBod);
oSession.url = "https://urltosendpostrequest.com/Search";
FiddlerObject.utilIssueRequest(oSession);
}

我希望服务器接受修改后的 POST 请求,但脚本遇到了错误。

FiddlerScript OnBeforeResponse0 failed. X 
There was a problem with your FiddlerScript. 
Function expected Function expected at Microsoft.)Script.Latainding.CallValue(Object val, Objects arguments, Boolean construct, Boolean brackets, VsaEngine engine, Object thisob, Binder binder, Culturelnfo culture, Strings namedParameters) at Microsoft.JScript.Latainding.Call(Binder binder, Objects arguments, ParameterModifier]] modifiers, Culturelnfo culture, Strings namedParameters, Boolean construct, Boolean brackets, VsaEngine engine) at Microsoft.JScript.Latainding.Call(ObjectS arguments, Boolean construct, Boolean brackets, VsaEngine engine) at Fiddler.ScriptNamespace.Handlers.OnBeforeResponse(Session oSession) at Fiddler.ScriptBase. 1:1(Session OD) in CA.lenkinsFiddler_WindowsworkspaceFiddler2CommonApplication ScriptingScriptBase.csiline 921 

您正在混合对请求和响应标头/正文的访问。此外,您似乎不清楚POST数据属于请求而不是响应。因此,请确保您正在操作正确的数据(请求或响应(。

还是要捕获请求并将自定义响应发送回客户端?如果是,您应该查看自动回复标志x-replywithfile

脚本包含OnBeforeResponse代码,因此只能访问与响应相关的属性和方法。 但是,您有以下代码尝试访问请求(这当然是不可能的,因为请求已经被转发(:

oSession.oRequest.headers.HTTPMethod == "POST";
oSession.utilSetRequestBody(reqBod);
FiddlerObject.utilIssueRequest(oSession);

最新更新