What url encoding web browser uses?

2019-08-30 05:59发布

问题:

What url encoding a web browser uses while submitting data to server? with my application i use HttpUtility.UrlEncode(string data) but do not get result as i get with web browser.

My application submit some text data to forum.

When i am submitting data with web browser (Google Chrome) the exact text i can see submitted to server but when i am submitting using my application it showing some character different.

So is this necessary to submit any data to server must be url encoded?

---Edit---

        data = HttpUtility.UrlEncode(textBox1.Text);

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.CookieContainer = cookieContainer;
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5";
        request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
        request.Headers.Add("Accept-Charset", "ISO-8859-2,utf-8;q=0.7,*;q=0.7");
        request.Headers.Add("Accept-Encoding", "gzip, deflate");
        request.Headers.Add("Accept-Language", "pl,en-us;q=0.7,en;q=0.3");
        request.Method = "POST";
        byte[] byteArray = new byte[256];
        ASCIIEncoding ascii = new ASCIIEncoding();
        byteArray = ascii.GetBytes(data);     

        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = byteArray.Length;
        Stream dataStream = request.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();

and data in textbox1 is like this.

¦=¦=¦¦=¦=¦
RUNTIME………..: 2h:13m:15s
RELEASE SIZE……: 16,2GB
VIDEO CODEC…….: x264, 2pass,

回答1:

You generally only have to URLEncode if you want to include a URL reserved charatcer (?, &, etc.) in a url parameter.