titanium-web-proxy icon indicating copy to clipboard operation
titanium-web-proxy copied to clipboard

Titanium Web Proxy - Can't modify request body

Open nikolapejic95 opened this issue 5 years ago • 5 comments

Hi everyone, I'm having a problem with modifying the requests before they reach the browser. I've posted the question on stack overflow, please check it out:

https://stackoverflow.com/questions/63508922/titanium-web-proxy-cant-modify-request-body

The solution might be obvious, but I don't seem to be able to find out how to fix it. Any help would be appreciated.

nikolapejic95 avatar Aug 20 '20 17:08 nikolapejic95

Is the onRequest called for your website?

The code on stackoverflow looks strange. I doubt that it is from the example from here. Why do you use Task.Run instead of simply awaiting that call? I think you should not call the GetResponseBody from the onRequest handler, since the request will be sent to the server only after this call...so you won't be able to get the response here.

honfika avatar Aug 20 '20 18:08 honfika

HI @honfika

thank you for the fast response!

Oh my God... I can't believe I've missed that :|

Putting modifications under onResponse works like a charm, thank you for the help!

By the way, I'm using Task.Run since await gives me "Cannot await void" for some reason. I'm using .NET 4.5

nikolapejic95 avatar Aug 20 '20 18:08 nikolapejic95

Yeah, because it is a symchronous method, in it unnecessary to wrap it in a task and await it... it just makes your code slower.

honfika avatar Aug 20 '20 19:08 honfika

help

bbhxwl avatar Sep 20 '20 14:09 bbhxwl

at the onRequest function of ProxyTestController. you can add if (e.HttpClient.Request.Method == "GET" || e.HttpClient.Request.Method == "POST") { var bodyBytes = await e.GetRequestBody(); e.SetRequestBody(bodyBytes);

            var body = e.GetRequestBodyAsString();
            
            //e.SetRequestBodyString(body.Result);
            if (body.Result.Contains("username")) {
                string _aloc = body.Result.Replace("xxx", "yyy");
                e.SetRequestBodyString(_aloc);
            }
            
        }

tungpcco avatar May 17 '21 14:05 tungpcco