Hello * Folks,
你好*人,
I'm new to Fiddler 2, but I seem to be getting along with it pretty good. Although I have one problem that I can't seem to solve.
我对Fiddler 2很陌生,但我似乎和它相处得很好。虽然我有一个问题我似乎解决不了。
What I want to do is actually very simple I think. I want to intercept a request, let it run, but if the response doesn't suit me I want it to resend the request and make the initial request nonexcistent. This using FiddlerScript.
我想做的其实很简单。我想要拦截一个请求,让它运行,但是如果响应不适合我,我希望它重新发送请求并使初始请求不受约束。这个使用FiddlerScript。
Why is this useful: in cases where you send a request but the response is different everytime. and you just want the right kind of response.
为什么这是有用的:在发送请求的情况下,每次响应都是不同的。你只需要正确的回应。
What I have so far:
到目前为止我所拥有的:
static function OnBeforeResponse(oSession: Session)
{
if (oSession.uriContains("/*example"))
{
if(oSession.GetRequestBodyAsString().Contains("GetRandomItem"))
{
if(oSession.GetResponseBodyAsString().ToString().Contains("ItemID"))
{
var body = oSession.GetResponseBodyAsString();
var item = 0;
for(var i = 0; i< body.Length; i++)
{
if(i < body.Length -7)
{
if(body.Substring(i, 6) == "ItemID")
{
item= Convert.ToInt32(body.Substring(i+7,1));
}
}
}
MessageBox.Show(item.ToString());
if(item < 2536) //for example itemid must be higher than 2536
{
//STOP / MAKE this session nonexcistent
//RESEND CURRENT REQUEST to get new response
oSession.state = SessionStates.SendingRequest;
FiddlerObject.utilIssueRequest(oSession.oRequest.ToString());
}
}
}
}
}
Every possible solution using Fiddlerscript is welcome.
使用Fiddlerscript的所有可能的解决方案都是受欢迎的。
Thank you * cummunity! (and Fiddler developers)
谢谢你* cummunity !(和提琴手开发人员)
1 个解决方案
#1
1
Setting the state of the Session back to SendingRequest doesn't do what you'd hope.
将会话的状态设置回SendingRequest并不能实现您所希望的。
Here's an example of the sort of thing you're trying to do. https://groups.google.com/forum/#!searchin/httpfiddler/retry/httpfiddler/3OZQVmQZdR0/uvqTyl3w2BAJ
这是你想做的事情的一个例子。https://groups.google.com/forum/ ! searchin / httpfiddler /重试/ httpfiddler / 3 ozqvmqzdr0 / uvqTyl3w2BAJ
if (!String.IsNullOrEmpty(oSession["X-RetryNumber"])) return;
for(var iRetry: int = 1; iRetry < 5; ++iRetry)
{
var oSD = new System.Collections.Specialized.StringDictionary();
oSD.Add("X-RetryNumber", iRetry.ToString());
var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);
if (200 == newSession.responseCode) // <--- UPDATE THIS TO WHATEVER YOU LIKE
{
// If we were successful on a retry, bail here!
oSession.oResponse.headers = newSession.oResponse.headers;
oSession.responseBodyBytes = newSession.responseBodyBytes;
oSession.oResponse.headers["Connection"] = "close"; // Workaround limitation
break;
}
}
#1
1
Setting the state of the Session back to SendingRequest doesn't do what you'd hope.
将会话的状态设置回SendingRequest并不能实现您所希望的。
Here's an example of the sort of thing you're trying to do. https://groups.google.com/forum/#!searchin/httpfiddler/retry/httpfiddler/3OZQVmQZdR0/uvqTyl3w2BAJ
这是你想做的事情的一个例子。https://groups.google.com/forum/ ! searchin / httpfiddler /重试/ httpfiddler / 3 ozqvmqzdr0 / uvqTyl3w2BAJ
if (!String.IsNullOrEmpty(oSession["X-RetryNumber"])) return;
for(var iRetry: int = 1; iRetry < 5; ++iRetry)
{
var oSD = new System.Collections.Specialized.StringDictionary();
oSD.Add("X-RetryNumber", iRetry.ToString());
var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);
if (200 == newSession.responseCode) // <--- UPDATE THIS TO WHATEVER YOU LIKE
{
// If we were successful on a retry, bail here!
oSession.oResponse.headers = newSession.oResponse.headers;
oSession.responseBodyBytes = newSession.responseBodyBytes;
oSession.oResponse.headers["Connection"] = "close"; // Workaround limitation
break;
}
}