Search code examples
javascriptxmlhttprequestfiddler

fiddler script send http request


i need to send http request in onBeforeResponse method.
i am trying to add this method in CustomRules.js

static function httpGet(theUrl){
    var xmlHttp = new XMLHttpRequest();
		xmlHttp.open( "GET", theUrl, false );
		xmlHttp.send( null );
		return xmlHttp.responseText;
	}

but i have an error "XMLHttpRequest" is not defined
There are any way how to send http request from fiddler script rule?


Solution

  • Fiddler doesn't have a browser object model, so XMLHttpRequest isn't defined. Fortunately, it offers many different ways to send HTTP requests; e.g.:

    var oSD = new System.Collections.Specialized.StringDictionary();
    var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);
    if (200 == newSession.responseCode)
    {
     //....
    }