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服务器的配置有关?
{
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服务器的配置有关?
解决方案 »
- 如何设置文本框不能输入
- C#编辑器 能来个精简版的不?不要这么大同时还能调试??
- 求助~DatagridView获取最后1行的行号~出代码
- (400分求解)数据上传的问题,一直没有想到好方案
- 有需要做tcp通讯的吗?试试我这个完成端口控件吧
- 简单问题/在线等待
- 菜鸟求助~C#如何获取当前用户的宽带账号
- c#入门问题
- TREEview的TEXT属性赋给一个文本框
- 怎样在Windows启动时也启动一个程序?
- winfrom程序窗口关门释放问题?
- (疑难杂症)在另外一个线程里面用了个messagebox,在主线程中调用Application.Exit();竟然无法把messagebox关掉........
DONE和ERROR是啥啊?
如不需要接收数据 用GET
还有下面这个属性加上看看
myWebRequest.ContentType=
如 "application/x-www-form-urlencoded";看你这里 stream 方式好像就成
myWebRequest.ContentType=
如 "application/x-www-form-urlencoded";text/html
text/xml
text/plain
都试过了
网页简单的贴出来看看吧 关键在网页上
对方收到的却是http://???.???.???.???:????/SUB-FDGW?id=???&action=H_GET_ANF&data=1231%7C
————————————————————————————————————//编码用这个试试//由网页输出
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312")
Response.Charset = "GB2312"
strUrl=System.Web.HttpUtility.UrlEncode(strUrl);
Response.BinaryWrite(strUrl);
这样它就不会自动编码了