我得到The underlying connection was closed: The connection was closed unexpectedly
错误而执行以下代码(Windows 8中,.NET 4.5):基础连接已关闭意外
link = @"http://login.rutracker.org/forum/index.php";
_request = new HttpRequestMessage(HttpMethod.Post, link);
_request.Headers.Add("User-Agent", "Chrome/22.0.1229.94");
_request.Headers.Add("Accept", "text/html");
var content = new Dictionary<string, string>();
content.Add("login_username", name);
content.Add("login_password", "pass");
_request.Content = new FormUrlEncodedContent(content);
_request.Content.Headers.ContentEncoding.Add("gzip");
_request.Content.Headers.ContentEncoding.Add("deflate");
_response = await _client.GetAsync(_request.RequestUri);
return await _response.Content.ReadAsByteArrayAsync();
我的目标是使请求相同以下(日志从Fiddler
应用):
POST /forum/login.php HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: http://rutracker.org/forum/index.php
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Content-Length: 71
DNT: 1
Host: login.rutracker.org
Pragma: no-cache
Cookie: spylog_test=1
login_username=myusername&login_password=mypass&login=%C2%F5%EE%E4
我试过发送/不发送头的各种组合,包括删除这些头,它仍然无法正常工作。 –
你可以通过使用你的代码发布你使用Fiddler获得的输出吗? – thedayofcondor