注册 登录
编程论坛 ASP.NET技术论坛

asp.net 前台向后台发送请求http.open()方法 后台如何接收到这些数据??

yhq448239218 发布于 2012-05-31 23:06, 1016 次点击
前台向后台发送请求代码为:  http=new XMLHttpRequest();  url="/AjaxServer.aspx?type=1&yhm="+escape(yhm)+"&mm="+mm;
        http.open("post",url,true);
        http.send();

后台如何获取到这数据呢?  有人说在对应的页面的
protected void Page_Load(object sender, EventArgs e)
    {
        string type;
        type = Request.QueryString["type"];
     }
这么写,就会获取到,  但是我在这里设置断点 根本不会命中断点,也就是说根本不会执行到这里, 求救该如何获取,求救啊……………………
6 回复
#2
yhq4482392182012-06-01 09:20
有了解过的嘛?  一起探讨一下呀
#3
wumingchenxi2012-06-06 13:16
以下例子可以参考。
Uri uri = new Uri("http://www.);   //目标网页
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
        request.Method = "POST";
        request.Timeout = 2000;
        request.KeepAlive = false;
        StringBuilder sb = new StringBuilder(250);
        sb.Append("login=");    //发送两个参数,login,pwd
        sb.Append(sloginid);
        sb.Append("&pwd=");
        sb.Append(spwd);

        byte[] sendbyte = Encoding.ASCII.GetBytes(sb.ToString());
        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = sendbyte.Length;
        Stream sendStream = request.GetRequestStream();
        if (sendStream.CanWrite)
        {
            sendStream.Write(sendbyte, 0, sendbyte.Length);
        }
        sendStream.Close();

        WebResponse response = request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new (responseStream);
        string srcString = reader.ReadToEnd();  //srcString就是想访问页面的,返回结果的网页源代码
#4
yms1232012-06-07 10:26
http.open("post",url,true);
        http.send();
你发送页面用post方式发送,接收页面用get肯定获取不到
type = Request.QueryString["type"];

你把发送页面改为
 http.open("get",url,true);
        http.send();
#5
yhq4482392182012-06-07 12:27
回复 3楼 wumingchenxi
嗯,谢谢、这个问题解决了,其实是我的url 中多了一个/   呵呵, 还是谢谢了!
#6
yhq4482392182012-06-07 12:28
回复 4楼 yms123
嗯,谢谢、这个问题解决了,其实是我的url 中多了一个/   呵呵, 还是谢谢了!  我用的就是post
#7
qmoneyg2012-06-13 21:40
没这样写过!
1