javascript - 将修改后的请求发送到服务器的 Fiddlerscript 不起作用
问题描述
我创建了一个 fiddlescript 规则,我认为它会等待特定的对象:值,自动将 json 值的一部分发送回不同的 URI,作为具有相同标头信息(如 cookie)的发布请求。
当脚本被激活时,我收到一个错误。我认为它与 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
解决方案
您正在混合访问请求和响应标头/正文。此外,您似乎不清楚POST
数据属于请求而不是响应。因此,请确保您正在处理正确的数据(请求或响应)。
还是您想捕获请求并将自定义响应发送回客户端?如果是,您应该查看AutoResponder Flagx-replywithfile
。
您的脚本中有代码,OnBeforeResponse
因此您只能访问与响应相关的属性和方法。但是,您有以下代码尝试访问请求(这当然是不可能的,因为请求已经被转发):
oSession.oRequest.headers.HTTPMethod == "POST";
oSession.utilSetRequestBody(reqBod);
FiddlerObject.utilIssueRequest(oSession);
推荐阅读
- python - 同时更新 theta0 和 theta1 以在 python 中计算梯度下降
- javascript - 材质 ui 具有相同定义的多个类名
- docker - Docker缓存存储位置
- javascript - 使用 2 步对数组进行排序
- python - 从第二个数据帧有效地映射熊猫中的值
- c++ - 如何插入一个额外的 QTableWidget
- javascript - Node js将文件下载到服务器到特定文件夹中
- azure - SharePoint 作为 Azure SQL 和 Blob 的表示层
- c++ - main.cpp 如何知道包含头文件的源文件?
- python - 如何在字典中的列表列表上迭代一个键?