C
C
CityzenUNDEAD2020-06-17 12:14:11
Parsing
CityzenUNDEAD, 2020-06-17 12:14:11

Why does the IDE write that the header of the request to the site is incorrect?

Hello everyone! I want to get the content of one site, it turned out that to get the page markup, you need to specify this in the request headers:
Accept: text/html,application/xhtml+xml,application/xml;
Accept-Encoding: gzip, deflate, br
As a result, the code has the following section:

System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)WebRequest.Create(url);
            req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36";
            //var reqProxy = ProxyBalancer.GetHttpRequest(out proxyAddress, out proxyIP, out proxyType, url, new int[] { 1 });
            req.Proxy = new WebProxy(reqProxy, true);
            req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            req.Headers.Add(HttpRequestHeader.Accept, "text/html, application/xhtml+xml, application/xml");
            //AddLogMessage("Proxy: " + proxyAddress, LogMessageType.Info); */
            req.AutomaticDecompression = DecompressionMethods.GZip;
            req.CookieContainer = cookies;
            
            System.Net.HttpWebResponse resp = (System.Net.HttpWebResponse)req.GetResponse();

IDE complains about req.Headers.Add(HttpRequestHeader.Accept.
System.ArgumentException: The "Accept" header needs to be changed with the appropriate property or method.
What did I write wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-06-17
@GavriKos

What did I write wrong?

Have you tried reading what the IDE writes?
HttpWebRequest has a separate Accept field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question