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