在C#中用哪个可以实现与js中XMLHttpRequest对象一样以get方式请求页面

解决方案 »

  1.   

    asp.net 用jquery 有内置方法
      

  2.   

    http://woxxf.blog.163.com/blog/static/18872912008428532852/
      

  3.   

    $.ajax({
                        type: "GET",
                        url: "/xxxx.ashx",
                        dataType: "html",
                        data: str,--url参数数据
                        success: function (msg) {
                            alert(msg);
                                                }
                    });
      

  4.   

    可以直接访问ashx文件后面加参数 xxx.ashx?id=1&name=abc
      

  5.   

    和普通的一样啊,如果你不用Jquery的话<script type="text/javasccript">
    var xmlHttp;
    function createXmlRequest()
    {
        if(window.ActiveXObject)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest)
            xmlHttp=new XMLHttpRequest();
    }
     
    function Startreadystate()
    {
    CreateXmlRequest();
    xmlHttp.onreadystatechange=handlerStateChange;
    xmlHttp.open("GET","/xxxx.ashx?参数名="+escape(document.getElementById("参数ID").value),true);
    xmlHttp.send(null);
    }
     
    function handlerStateChange()
    {
    if(xmlHttp.readystate=="4" && xmlHttp.status=="200")
    {
        if(xmlHttp.responseText!="")
        {
            document.getElementById("ID").innerText=xmlHttp.responseText;
        }
    }
    }
    </script>
      

  6.   

    lz问的是C#程序怎么访问.ashx页面吧,WebClient或者HttpWebRequest都可以
      

  7.   


            StringBuilder builder = new StringBuilder();
            builder.Append("http://xxx.com.cn/misc.ashx");
            builder.Append("?");
            builder.Append("action=gold");
            builder.Append("&");
            builder.Append("token="+strToken+"");
            HttpWebResponse rsp = null;
            HttpWebRequest req = null;
            req = (HttpWebRequest)WebRequest.Create(new Uri(builder.ToString()));
            req.ContentType = "application/x-www-form-urlencoded";
            req.Accept = "*/*";
            req.Timeout = 30000;//30秒连接不成功就中断 
            req.Method = "GET";
            rsp = (HttpWebResponse)req.GetResponse();
            Stream rspStream = rsp.GetResponseStream();        StreamReader sr = new StreamReader(rspStream, Encoding.GetEncoding("utf-8"));
            result = sr.ReadToEnd();
            sr.Close();
           
            XmlDocument xmlDoc = new XmlDocument();        xmlDoc.LoadXml(result);
      

  8.   


      StringBuilder builder = new StringBuilder(); 
            builder.Append("http://xxx.com.cn/misc.ashx"); 
            builder.Append("?"); 
            builder.Append("action=gold"); 
            builder.Append("&"); 
            builder.Append("token="+strToken+""); 
            HttpWebResponse rsp = null; 
            HttpWebRequest req = null; 
            req = (HttpWebRequest)WebRequest.Create(new Uri(builder.ToString())); 
            req.ContentType = "application/x-www-form-urlencoded"; 
            req.Accept = "*/*"; 
            req.Timeout = 30000;//30秒连接不成功就中断 
            req.Method = "GET"; 
            rsp = (HttpWebResponse)req.GetResponse(); 
            Stream rspStream = rsp.GetResponseStream();         StreamReader sr = new StreamReader(rspStream, Encoding.GetEncoding("utf-8")); 
            result = sr.ReadToEnd(); 
            sr.Close(); 
          
            XmlDocument xmlDoc = new XmlDocument();         xmlDoc.LoadXml(result); 
      

  9.   


    StringBuilder sb = new StringBuilder();
    sb.Append("CashChargeStationDailyReport.ashx");
    sb.Append("?StationID=" + onPack.StationID);
    sb.Append("&ReportDate=" + onPack.ReportDate);HttpWebRequest request = null;
    request = (HttpWebRequest)WebRequest.Create(new Uri(sb.ToString()));
    请问:最后一行代码出错:无效的 URI: 无法确定 URI 的格式。
    怎么写这个参数。