1
votes

edit: I'm also not convinced HttpListener does anything

  1. So response headers != request headers for the next post.
  2. Why does a browser begin with correct request headers, but a simple GET HTTP / 1.1 from my client not look the same even tho the originating request headers change per domain a lot of times???????
  3. This doesn't use the cookies properly either. Why is that?

How do I work something to give me this browser magic?

*WebClient has no .RequestHeaders.

*Comparing HttpWebRequest headers to Chrome/Fiddler sniffing.

using System.Net;
    private void Form1_Load(object sender, EventArgs e)
    {
        CookieContainer cookieJar = new CookieContainer();
        cookieJar.GetCookies(new Uri("https://www.google.com"));
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com");
        request.CookieContainer = cookieJar;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();


        this.Text = request.Headers.Count.ToString();
            WebHeaderCollection header = request.Headers;
            for (int i = 0; i < header.Count; i++)
            {
                richTextBox1.AppendText(header.GetKey(i) + ": " + header[i] + "\n");
            }
    }

Fiddler/Chrome combo returns 10 Request headers; The client returns 2.

Also why does a header "Accept-Encoding: gzip,deflate,sdch" always make the response some weird 2 character flop of data?

1
Sniffed/Compared with Fiddler - ploxtic
Until someone knows something. - ploxtic
Man, I'm so tired of this "cookie jar" joke. I wish people would get over it and just use a proper variable name. - usr

1 Answers

0
votes

It's not quite clear what you are trying to achieve but the WebClient has a Headers property that you could use to make the request headers look as you wish:

using (var client = new WebClient())
{
    client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22";
    client.Headers[HttpRequestHeader.AcceptLanguage] = "fr-FR,fr;q=0.8";
    ... you could set here whatever headers you want

    string result = client.DownloadString("http://www.google.com");
}