對於使用HttpWebRequest的POST請求,當我寫入請求流時,數據在什麼時候發送?當我關閉請求流或當我調用GetResponse時?是否需要GetResponse調用?是否需要HttpWebRequest.GetResponse才能完成POST?
的.NET文檔似乎並不約爲究竟發生什麼事
很清楚下面的代碼我很好奇:
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentLength = jsonData.Length;
request.ContentType = "application/json";
Stream requestStream = request.GetRequestStream();
requestStream.Write(jsonData, 0, jsonData.Length);
requestStream.Close();
var response = request.GetResponse() as HttpWebResponse;
謝謝!
您需要獲得響應*無論如何*閱讀狀態代碼,並確定您的「POST」是否被服務器接受或拒絕... –