在做采集时:采集对方的数据时:一定要用POST的提交方式,请问用POST如何使用代理IP呢,我是这样写的,但是报操作超时的异常
try
{
Encoding encoding = Encoding.GetEncoding("utf-8");
Uri uri = new Uri(action);
byte[] paramBytes = encoding.GetBytes(parmString);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(uri);
if (ip != "")
{
WebProxy proxyObject = new WebProxy(ip, port);
wr.Proxy = proxyObject;
wr.Timeout = 5000;
}
wr.ContentType = "application/x-www-form-urlencoded";
wr.Method = "POST";
using (Stream stream = wr.GetRequestStream())
{
stream.Write(paramBytes, 0, paramBytes.Length);
}
WebResponse webResponse = wr.GetResponse();
using(StreamReader reader = new StreamReader(webResponse.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (Exception ex)
{
return ex.Message;
}
还需要账号和密码
不是吧,我用另外一种方法解决了,谢谢
hw.Headers.Set("Pragma", "no-cache");
hw.UserAgent = "Mozilla-Firefox-Spider(Wenanry)";加了这两句