我在.net和POST數據中使用WebRequest類到正在響應響應的服務器。WebRequest問題,請求主體之前的響應
奇怪的是,當我開始小提琴手分析我的網絡流量時,它的工作,但沒有小提琴手它不是。
因此,我開始分析使用WireShark發送到計算機和從計算機發送的包。在這個程序中,它很容易遵循TCP流。所以當我開着小提琴時,我可以看到發送了正確的Request-header/body,並獲得Response-header/body。奇怪的部分是當我不使用fiddler發送Request-header時,那麼我得到了Response-header/body,最後是TCP-stream結尾的request-body。
這裏是我的代碼,我已經闡述:
string lcUrl = "http://XX.XX.XXX.XX";
// *** Establish the request
HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(lcUrl);
string lcPostData = testdata;
loHttp.Method = "POST";
byte [] lbPostBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;
loHttp.Credentials = CredentialCache.DefaultCredentials;
//loHttp.SendChunked = true;
loHttp.ServicePoint.Expect100Continue = false;
Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length);
loPostData.Close();
HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);
string lcHtml = loResponseStream.ReadToEnd();
loWebResponse.Close();
loResponseStream.Close();
也許這有助於:http://stackoverflow.com/questions/18126941/c-sharp-webrequest-post-and-getresponse – xameeramir 2014-05-07 14:59:52