HttpWebRequest 到 avito.ru -> 错误
HttpWebRequest to avito.ru -> error
需要从以下任意添加中获取 HTML:https://www.avito.ru/moskva/kvartiry?user=1
我有以下代码:
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
Request.ProtocolVersion = HttpVersion.Version11;
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
Request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*;q=0.8";
Request.Headers.Add(HttpRequestHeader.AcceptLanguage, "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
Request.Method = "GET";
Request.Timeout = 10000;
using (HttpWebResponse Response = (HttpWebResponse)Request.GetResponse()) { ...;}
直到今天,它都可以正常工作。显然他们在他们的网站上做了一些更改,现在代码的最后一行抛出一个错误,上面写着:
System.Net.WebException: Base connection is closed: inexpected error at transfer. ---> System.IO.IOException: connection error because of inexpected packet format.
问题是,我仍然从顶部的 link 那里得到了很好的回应。
但是它会在 https://www.avito.ru/moskva/kvartiry/2-k_kvartira_54_m_1617_et._555913941
之类的响应时抛出异常
- 浏览器请求得到应有的响应。即使禁用 cookie 和 JS。
有什么想法吗?
ps。错误消息在翻译时可能不准确。我的语法借口..
服务器放弃了我的请求,因为我忘记将 "www." 添加到组成 url 的域名中..
小伙伴们注意细节。
需要从以下任意添加中获取 HTML:https://www.avito.ru/moskva/kvartiry?user=1
我有以下代码:
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(url);
Request.ProtocolVersion = HttpVersion.Version11;
Request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
Request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*;q=0.8";
Request.Headers.Add(HttpRequestHeader.AcceptLanguage, "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
Request.Method = "GET";
Request.Timeout = 10000;
using (HttpWebResponse Response = (HttpWebResponse)Request.GetResponse()) { ...;}
直到今天,它都可以正常工作。显然他们在他们的网站上做了一些更改,现在代码的最后一行抛出一个错误,上面写着:
System.Net.WebException: Base connection is closed: inexpected error at transfer. ---> System.IO.IOException: connection error because of inexpected packet format.
问题是,我仍然从顶部的 link 那里得到了很好的回应。
但是它会在 https://www.avito.ru/moskva/kvartiry/2-k_kvartira_54_m_1617_et._555913941
之类的响应时抛出异常- 浏览器请求得到应有的响应。即使禁用 cookie 和 JS。
有什么想法吗?
ps。错误消息在翻译时可能不准确。我的语法借口..
服务器放弃了我的请求,因为我忘记将 "www." 添加到组成 url 的域名中.. 小伙伴们注意细节。