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();

}
...全文
557 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyun0112 2014-02-10
  • 打赏
  • 举报
回复
用fiddler看看浏览器发送的数据和你的有什么不同

*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧