我要发送一个http请求并获得对方服务器的响应值
我之前调用一个组件里的方法,在我本地测试都是ok的,但在服务器上就报组件错误(未将对象引用设置到对象的实例和 XMLHttpRequest 发送数据错误 ),于是我就换了这个
XMLHTTPClass myXMLHTTP = new XMLHTTPClass();
string url = http:xxxx
myXMLHTTP.open("GET", url, false, "", "");
myXMLHTTP.send(null);
string result = myXMLHTTP.responseText.Trim();
还是在我本地没错,在服务器上还是报错(未将对象引用设置到对象的实例)
因为我们服务器现在不能动,不能任意更该组件,所以我只能换其他的方法,其他的方法怎么写啊?

解决方案 »

  1.   

    c#中完全能够实现的功能,楼主为什么要调用系统的msxml组件呢?
    服务器上没有这个组件也是正常的。
      HttpWebRequest wres = WebRequest.Create("http://edu.sina.com.cn/bbs/2007/1017/1411014865.html") as HttpWebRequest;  WebResponse webResponse = wres.GetResponse();
      long l = webResponse.ContentLength;
      Uri u = webResponse.ResponseUri;
      System.IO.StreamReader sr = new System.IO.StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));  string result = sr.ReadToEnd();
      

  2.   

    string param = "";   
    byte[] bs = Encoding.ASCII.GetBytes(param);   
    HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" ); 
    req.Method = "POST";   
    req.ContentType = "application/x-www-form-urlencoded";   
    req.ContentLength = bs.Length;   
    using (Stream reqStream = req.GetRequestStream())   
    {}