此代碼使用Web客戶端通過HTTPS發送請求 - POST日期加倍
using (WebClient webClient = new WebClient())
{
string address = "https://www.any.com/name.htm";
byte[] postData = Encoding.ASCII.GetBytes("login=123");
webClient.Headers[HttpRequestHeader.Accept] = "text/html, application/xhtml+xml, */*";
webClient.Headers[HttpRequestHeader.AcceptLanguage] = "ru-RU";
webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
webClient.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webClient.UploadData(address, postData);
}
產生該請求(POSTDATA加倍):
POST /name.htm HTTP/1.1
Accept-Language: ru-RU
Accept-Encoding: gzip, deflate
Accept: text/html, application/xhtml+xml, */*
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host: [url]www.any.com[/url]
Content-Length: 9
Connection: Keep-Alive
login=123login=123
如果更改
string address = "https://www.any.com/name.htm"
到
string address = "http://www.any.com/name.htm"
然後數據不會加倍。
HTTPS發送請求時如何避免數據翻倍?
我剛剛通過一個使用Fiddler2的測試來運行它,它沒有重複數據。聽起來這個問題在別的地方。 – Hardrada
我看到了HttpAnalizer6的請求體。可能是這個是HttpAnalizer的bug ... – meng
這是可能的。你可以嘗試Fiddler2,看看結果是什麼比較。 – Hardrada