HttpClient のような新しいクラスを導入する新しい Framework .Net 4.5 をテストしています。vbulletin フォーラムにログインして件名を投稿しようとしています。
WampServer を使用すると完全に動作しますが、Nginx で試してみると、411 エラー、Content-Lenght Required が発生しました。
これは私のコードです:
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を見ましたが、サーバーを変更したくありません..
助けてくれてありがとう..