Http請求中的body是哪部分?
以HttpWebRequest為列,應該如何設置
HttpWebRequest req = WebRequest.Create("http://cn.bing.com") as HttpWebRequest;
req.ContentType = "application/x-www-urlencoded";
req.Method = "POST";
using (StreamWriter st = new StreamWriter(req.GetRequestStream()))
{
st.Write("http post request body"); // 請求體
}
using (StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream()))
{
string responseBody = sr.ReadToEnd(); // 響應體
}
講道理
之後的所有內容都是body
util length == content-length
The headers are terminated by a blank line (CRLF), marking the end of the list of headers and the beginning of the entity body.
-- 《HTTP The Definitive Guide》
HTTP報文中首部之後會有一個CRLF 之後的內容就是body啊
推薦閱讀:
※.NET Core是否會取代.NET Framework?
※如何在 WPF 或 UWP 應用中實現動態背景?
※如何提升ASP.NET網站首次打開速度?
※WPF繪製圖表時,1ms更新一次數據,界面變得特別卡?
※Node.js和.Net 4.5下的await、async相比有什麼不同?