Fiddlerscript发送修改的请求到服务器将无法正常工作

时间:2019-09-23 03:05:04

标签: javascript json http post fiddler

我创建了一个fiddlescript规则,我认为它将等待特定的object:value,将json值的一部分作为具有相同标头信息(例如cookie)的发布请求自动发送回不同的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.lenkins\Fiddler_Windows\workspace\Fiddler2\Common\Application\ Scripting\ScriptBase.csiline 921 

1 个答案:

答案 0 :(得分:0)

您正在混合访问请求和响应标头/正文。同样,您似乎还不清楚POST数据属于请求而不是响应。因此,请确保您要处理正确的数据(请求或响应)。

还是要捕获请求并将自定义响应发送回客户端?如果是,则应查看AutoResponder Flag x-replywithfile

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

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