zoukankan      html  css  js  c++  java
  • 服务端无法获取到Ajax发送post请求的参数

    js类似于这样:

    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”时的参数。

    但要想获得这些参数可以Request.InputStream得到:

    if (Request.InputStream.Length>0)
                {
                    StreamReader sr = new StreamReader(Request.InputStream);
                    var requestStr = sr.ReadToEnd();
                }

    参考http://bbs.csdn.net/topics/330125738

  • 相关阅读:
    lc377完全背包问题
    lc650
    lc583
    java static序列化
    lc90回溯
    lc78回溯
    Java基础之常量池
    语法与语义
    数据结构之复杂度分析
    数据结构与算法前言
  • 原文地址:https://www.cnblogs.com/rgshare/p/3159931.html
Copyright © 2011-2022 走看看