js相似於這樣:app
function send() { var xhr = new XMLHttpRequest(); xhr.open("post", "AjaxTest.aspx", true); //xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if (xhr.readyState===4) { alert("接受到的文本是:"+xhr.responseText); } } xhr.send("name=" + document.getElementById("name").value); }
因爲在發送請求的時候沒有指定Content-Type,因此用不管時用Request.Form沒法得到這些參數,由於Request.Form只會解析Content-Type 值爲「application/x-www-form-urlencoded」或「multipart/form-data」時的參數。post
但要想得到這些參數能夠Request.InputStream獲得:url
if (Request.InputStream.Length>0) { StreamReader sr = new StreamReader(Request.InputStream); var requestStr = sr.ReadToEnd(); }