justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.92k stars 598 forks source link

The URL parameter with Chinese characters comes to the upstream proxy like this "????" #931

Open dimansound opened 1 year ago

dimansound commented 1 year ago

Broken url parameter comes to upstream proxy when use UpStreamHttpProxy and Chinese characters in url params, for example any url with this params:

&systemCode=附件系统 or &systemCode=%E9%99%84%E4%BB%B6%E7%B3%BB%E7%BB%9F

On the upstream proxy got &systemCode=???? image BeforeRequest by default, hasn't code. Without UpStreamHttpProxy works well done. Titanium version 3.1.1450

dimansound commented 1 year ago

image

honfika commented 1 year ago

Do you change the url (or the query string ) in TWP? I tried to repducuce the issue, but can't ... however I did not change anything in TWP chrome => TWP => Fiddler => server works:

Browser: image

Upstream Http proxy (Fiddler): image

So please specify what did you do in your application.

dimansound commented 1 year ago

Do you change the url (or the query string ) in TWP?

I changed code url = Request.RequestUri.ToString() to url = Request.RequestUriString; Request.RequestUri.ToString() got ?systemCode=附件系统 Request.RequestUriString got ?systemCode=%E9%99%84%E4%BB%B6%E7%B3%BB%E7%BB%9F Otherwise, this is what happens: In original code TWP v3.2 in HttpWebClient.cs used this method (condition when useUpstreamProxy = true) url = Request.RequestUri.ToString(); So this method returned not urlencoded value of url http://.../?systemCode=附件系统 Next step in method headerBuilder.WriteRequestLine(Request.Method, url, Request.HttpVersion);

image

image

As a result, due to the fact that Request.RequestUri.ToString() returns an unencoded value, when encoding, the result is encoding.GetBytes(str) = "????", that is, instead of Chinese characters, since ISO-8859-1 is used, Chinese characters are encoded as the character "?"