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

3 posts, 1 answers
  1. JohnPetritisERDAS
    JohnPetritisERDAS avatar
    2 posts
    Member since:
    Jul 2015

    Posted 30 Jul 2015 Link to this post

    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. Answer
    Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 30 Jul 2015 Link to this post

    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
  3. JohnPetritisERDAS
    JohnPetritisERDAS avatar
    2 posts
    Member since:
    Jul 2015

    Posted 30 Jul 2015 Link to this post

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

Back to Top