public string GetPageSource(string url,int timeout)
{
string str="";
         WebRequest myWebRequest=WebRequest.Create(url);
myWebRequest.Timeout=timeout;
         //myWebRequest.Method="POST";  "GET"也试过了            
if(System.Configuration.ConfigurationSettings.AppSettings["proxy"]!=null)
{
       WebProxy proxy=new WebProx(System.Configuration.ConfigurationSettings.AppSettings["proxy"],true);
       myWebRequest.Proxy=proxy;
}
try
{
WebResponse myWebResponse=myWebRequest.GetResponse();
Stream resStream = myWebResponse.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.GetEncoding("GB2312"));
str=sr.ReadToEnd();
resStream.Close(); 
sr.Close();
return str;
}
catch
{

         return "pageerror";
}
}
在网页中直接获取结果为DONE,在程序中却为ERROR 
会不会跟url服务器的配置有关?

解决方案 »

  1.   

    对阿 但是在同一台机器 测试阿 而且该机器的公网IP服务器已经配置允许访问 如果没有配置允许 IE获取也不会成功的
      

  2.   

    什么情况返回DONE?什么情况应该是ERROR?
    DONE和ERROR是啥啊?
      

  3.   

    而且服务器也仅仅对ip进行验证,不对具体浏览器来源的进行验证ps:help
      

  4.   

    DONE和ERROR都是返回的结果字符串
      

  5.   

    先确认网页的访问方式 是否需要接收数据,接收的方式又是什么
    如不需要接收数据 用GET
    还有下面这个属性加上看看
    myWebRequest.ContentType= 
    如 "application/x-www-form-urlencoded";看你这里 stream 方式好像就成
      

  6.   

    访问方式get
    myWebRequest.ContentType= 
    如 "application/x-www-form-urlencoded";text/html
    text/xml
    text/plain
    都试过了
      

  7.   

    网页是啥  你用的那几中方式 好像都是post方式的
    网页简单的贴出来看看吧  关键在网页上
      

  8.   

    我们这边用http://???.???.???.???:????/SUB-FDGW?id=???&action=H_GET_ANF&data=1231|请求
    对方收到的却是http://???.???.???.???:????/SUB-FDGW?id=???&action=H_GET_ANF&data=1231%7C
      

  9.   

    能不能不让WebRequest的Url进行自动编码?
      

  10.   

    我怎么理解为编码问题了?
    ————————————————————————————————————//编码用这个试试//由网页输出
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
    Response.Charset = "GB2312"
    strUrl=System.Web.HttpUtility.UrlEncode(strUrl);
    Response.BinaryWrite(strUrl);
      

  11.   

    这些试过了ps:在哪里可以设置不让WebRequest请求自动编码么?唉 麻烦大家乐
      

  12.   

    gameover WebRequest myWebRequest=WebRequest.Create(new Uri(url,true));
    这样它就不会自动编码了