我正在测试引入新类的新 Framework .Net 4.5,例如 HttpClient。我正在尝试登录 vbulletin 论坛并发布主题。
它使用 WampServer 可以完美运行,但是当我尝试使用 Nginx 时出现 411 错误,需要 Content-Lenght。
这是我的代码:
HttpClient client = new HttpClient();
/* login part skipped, it works */
postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("do", "postthread"));
postData.Add(new KeyValuePair<string, string>("f", "8"));
postData.Add(new KeyValuePair<string, string>("loggedinuser", "1"));
postData.Add(new KeyValuePair<string, string>("message", "myMessage"));
postData.Add(new KeyValuePair<string, string>("subject", "mySubject : " + new Random().Next()));
postData.Add(new KeyValuePair<string, string>("securitytoken", secure_id));
postData.Add(new KeyValuePair<string, string>("vbseo_is_retrtitle", "1"));
postData.Add(new KeyValuePair<string, string>("vbseo_retrtitle", "1"));
postData.Add(new KeyValuePair<string, string>("posthash", posthash));
postData.Add(new KeyValuePair<string, string>("poststarttime", poststarttime));
HttpContent content = new FormUrlEncodedContent(postData);
HttpRequestMessage msg3 = new HttpRequestMessage(HttpMethod.Post, "http://localhost/newthread.php?do=postthread&f=8");
// Adding all headers from the resp2, containing cookie value to stay connected
// I think, here is the problem, when passing the 'Transfer-Encoding' and 'Transfer-EncodingChunked' values
foreach (var header in resp2.Headers)
msg3.Headers.Add(header.Key, header.Value);
msg3.Content = content;
var resp3 = client.SendAsync(msg3).Result;
resp3.EnsureSuccessStatusCode();
string html = resp3.Content.ReadAsStringAsync().Result;
当我看到 msg3.Content.Headers.ContentLength 时,我有一个值.. 所以我不明白为什么 Nginx 会抛出这个错误:/
谷歌搜索后,我看到了http://wiki.nginx.org/HttpChunkinModule但我不想修改服务器..
谢谢你的帮助..