This is a migrated thread and some comments may be shown as answers.

How can I script a change from a GET to POST ?

2 Answers 737 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
JohnPetritisERDAS
Top achievements
Rank 1
JohnPetritisERDAS asked on 30 Jul 2015, 01:32 PM

As I await the client to be updated to do a POST instead of a GET, I would like to use fiddler to change it on the fly for me.

I have code in OnBeforeRequest that makes changes in parameter names, but I still need to convert the call from a GET to a POST and I cannot find any methods that will switch it for me.

 How can I switch a GET to a POST in Fiddler Script?

2 Answers, 1 is accepted

Sort by
0
Accepted
Eric Lawrence
Telerik team
answered on 30 Jul 2015, 04:54 PM
Inside your OnBeforeRequest method, you'll use code like:

  if (oSession.urlContains("/whateverGETIWantToEdit.asp") &&
      (oSession.oRequest.headers.HTTPMethod == "GET"))
  {
     oSession["ui-backcolor"] = "green";   // Simplify debugging
     oSession.oRequest.headers.HTTPMethod == "POST";
     oSession.oRequest["Content-Type"] = "application/x-www-form/urlencoded";
     oSession.utilSetRequestBody("NewPostBodyValues=GoHere");
  } 


Regards,
Eric Lawrence
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
JohnPetritisERDAS
Top achievements
Rank 1
answered on 30 Jul 2015, 06:00 PM

Great! that was the information I needed.

FYI here is the fully functional code to change from a GET to a POST, and change some URL encoded parameters to get rid of a j_ prefixes that I no longer needed:

 

        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());
        }

Tags
Fiddler Classic
Asked by
JohnPetritisERDAS
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
JohnPetritisERDAS
Top achievements
Rank 1
Share this question
or