Tôi đang cố gắng để gửi một HttpWebRequest sử dụng một proxy tor với ứng dụng asp.net của tôi và tôi nhận được thông báo lỗi này khi gọi các webresponse.GetResponse) phương pháp (:Máy chủ đã vi phạm giao thức. Section = ResponseStatusLine khi sử dụng một tor Proxy
The server committed a protocol violation. Section=ResponseStatusLine
Tôi đã thử tìm kiếm giải pháp trên web và tôi tìm thấy 3 giải pháp chính cho lỗi này:
Thêm vào Web.config.
<system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true"/> </settings> </system.net>`
Thêm dòng:
webRequest.ProtocolVersion = HttpVersion.Version10;
vào mã.- Thêm dòng
request.ServicePoint.Expect100Continue = false;
vào mã.
Mỗi giải pháp được liệt kê không thay đổi điều gì về thông báo lỗi.
Dưới đây là đoạn code yêu cầu:
WebRequest.DefaultWebProxy = new WebRequest("127.0.0.1:9051");
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.CookieContainer = new CookieContainer();
webRequest.ProtocolVersion = HttpVersion.Version10;
webRequest.KeepAlive = false;
webRequest.Method = "GET";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19";
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());
string html = streamReader.ReadToEnd();
webResponse.Close();
return html;
bất cứ ai có thể giúp tôi tìm một giải pháp cho việc này?
Tôi đã thử thêm các dòng này nhưng trạng thái không phải là lỗi giao thức mà là ServerProtocolViolation. –
Thật vậy, Trả lời là không cho ngoại lệ của tôi: ( –
Cùng một vấn đề ở đây. Phản hồi là không. – tnktnk