Search code examples
fiddler

How do I change a GET to a POST using Fiddler scripting?


I have dug around and cannot find any way to get a GET into a POST using Fiddler. Given all the rest of what it does I expect there is some way to do it. I have written enough Fiddler script to find the right URL and start manipulating it, but not that last bit. The reason I need to do this is that a web client I am working with needs to change the way it sends credentials, but another group handles it and it will take some time for them to get to it. Here is the code that I have so far:

        if (oSession.fullUrl.Contains("j_spring_security_check") > -1)
    {
        var newUrl:String;
        newUrl = oSession.fullUrl;
        if (newUrl.Contains("j_username"))
            newUrl = newUrl.Replace("j_username", "username");
        if (newUrl.Contains("j_password"))
            newUrl = newUrl.Replace("j_password", "password");
        FiddlerObject.alert(newUrl);
        // ### I need to change it from a GET to POST here ###
        FiddlerObject.alert(newUrl);
    }

Solution

  • An admin over on a Fiddler message board gave me enough information to work this out. Here is the working solution:

            if (oSession.fullUrl.Contains("j_spring_security_check") && 
            oSession.fullUrl.Contains("j_username") &&
            oSession.HTTPMethodIs("GET"))
        {
            var newUrl:String;
            newUrl = oSession.fullUrl;
            if (newUrl.Contains("j_username"))
                newUrl = newUrl.Replace("j_username", "username");
            if (newUrl.Contains("j_password"))
                newUrl = newUrl.Replace("j_password", "password");
            FiddlerObject.alert(newUrl);
    
            oSession.oFlags["ui-backcolor"] = "lightgreen"; // jbp for debug use
            oSession.oRequest.headers.HTTPMethod = "POST";
            oSession.oRequest["Content-Type"] = "application/x-www-form/urlencoded";
            oSession.utilSetRequestBody("");
    
            oSession.fullUrl = newUrl;
    
            FiddlerObject.alert(oSession.fullUrl.ToString());
        }