C#使用WebProxy出现的问题

小小小的程序员 开发  2014-02-09 11:29:25

System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)WebRequest.Create(url);
WebProxy pr = new WebProxy("124.40.121.3", 80);
pr.BypassProxyOnLocal = true;
pr.Credentials = CredentialCache.DefaultCredentials;
request.Proxy = pr;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string encoding = "bg2312";
string returl = "http://app1.vote.cntv.cn/viewResult.jsp?voteId=12384";
string formhash = "69256b23";
string voteId = "12384";
string type = "html";
string items_1118821 = "131940";
string paraUrlCoded = "encoding=" + encoding + "&returl=" + returl + "&formhash=" + formhash + "&voteId=" + voteId + "&type=" + type + "&items_1118821=" + items_1118821;
byte[] payload;
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
request.ContentLength = payload.Length;
Stream writer = request.GetRequestStream();
writer.Write(payload, 0, payload.Length);
writer.Close();
System.Net.HttpWebResponse response;
try
{
response = (System.Net.HttpWebResponse)request.GetResponse();
//问题就出在这里了 总是异常 说远程服务器返回错误 404未找到
//不用代理不报错 可以正常运行 用浏览器使用代理也正常
}
catch (Exception e)
{
return e.ToString();

}
...全文
308 点赞 收藏 1
写回复
1 条回复
feiyun0112 2014年02月10日
用fiddler看看浏览器发送的数据和你的有什么不同

*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
回复 点赞
发动态
发帖子
C#
创建于2007-09-28

8.4w+

社区成员

64.0w+

社区内容

.NET技术 C#
社区公告
暂无公告