返回首页
当前位置: 首页 > 服务器安全 >

HttpWebResponse 远程服务器返回错误: (403) 已禁止

时间:2013-03-25 10:50来源:未知 作者:admin 点击:我要投稿  高质量的ASP.NET空间,完美支持1.0/2.0/3.5/4.0/MVC等

GET形势获取URL的返回值出现对访问同一URL过于频繁就会出现403已禁止 

1    string result = "";
2    HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(strUrl);            
3    HttpWebResponse respone = (HttpWebResponse)httpRequest.GetResponse();
4    StreamReader stream = new StreamReader(respone.GetResponseStream(), Encoding.UTF8);
5    result = stream.ReadToEnd();

解决方案加个获取身份验证信息

 
1  string result = "";
2  HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(strUrl);
3  httpRequest.Timeout = 10000;
4  httpRequest.UserAgent = "Code Sample Web Client";
5  httpRequest.Credentials = CredentialCache.DefaultCredentials;
6  HttpWebResponse respone = (HttpWebResponse)httpRequest.GetResponse();
7  StreamReader stream = new StreamReader(respone.GetResponseStream(), Encoding.UTF8);
8  result = stream.ReadToEnd();

 

本站推荐文章:
本站热点文章:
顶一下
(2)
100%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色 情、暴力、反动的言论。
评价:
表情:
用户名:密码: 验证码:点击我更换图片