An exception occurred during a WebClient request_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > An exception occurred during a WebClient request

An exception occurred during a WebClient request

 2015/3/23 10:59:45  麻将我会  程序员俱乐部  我要评论(0)
  • 摘要:System.Net.WebExceptionwascaughtHResult=-2146233079Message=AnexceptionoccurredduringaWebClientrequest.Source=SystemStackTrace:atSystem.Net.WebClient.OpenRead(Uriaddress)atSystem.Net.WebClient.OpenRead(Stringaddress)atClient.Program.GetAllEmployees
  • 标签:Web client

System.Net.WebException was caught
HResult=-2146233079
Message=An exception occurred during a WebClient request.
Source=System
StackTrace:
at System.Net.WebClient.OpenRead(Uri address)
at System.Net.WebClient.OpenRead(String address)
at Client.Program.GetAllEmployees(String contentType, String accept) in h:\帮助页面与自动消息格式(JSONXML)选择\Client\Program.cs:line 62
InnerException: System.Configuration.ConfigurationErrorsException
HResult=-2146232062
Message=Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section.
Source=System
BareMessage=Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section.
Line=0
StackTrace:
at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
at System.Net.WebRequest.get_InternalDefaultWebProxy()
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.OpenRead(Uri address)
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An invalid argument was supplied
Source=System
ErrorCode=10022
NativeErrorCode=10022
StackTrace:
at System.Net.SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, Boolean autoReset, Boolean signaled)
at System.Net.NetworkAddressChangePolled..ctor()
at System.Net.AutoWebProxyScriptEngine.AutoDetector.Initialize()
at System.Net.AutoWebProxyScriptEngine.AutoDetector.get_CurrentAutoDetector()
at System.Net.AutoWebProxyScriptEngine..ctor(WebProxy proxy, Boolean useRegistry)
at System.Net.WebProxy.UnsafeUpdateFromRegistry()
at System.Net.WebProxy..ctor(Boolean enableAutoproxy)
at System.Net.Configuration.DefaultProxySectionInternal..ctor(DefaultProxySection section)
at System.Net.Configuration.DefaultProxySectionInternal.GetSection()
InnerException:

 

上述的错误来自于下面的代码:

class="brush:csharp;gutter:true;"> WebClient webClient = new WebClient();

             
                var stream = webClient.OpenRead("http://www.cnblogs.com/");
                using (StreamReader reader = new StreamReader(stream))
                {
                    Console.WriteLine(reader.ReadToEnd());
                }

  

上面的错误让我纠结了好久,仅仅是一个简单的webclient请求,怎么都不通??

百度了一个办法?

http://codebender.denniland.com/system-net-webexception-an-exception-occurred-during-a-webclient-request/

试了,还是不行,看到了system.net/defaultProxy 关键词,以为是公司网络问题,于是下班之后在家里的网络试了一下,

竟然代码通过了,所以我的怀疑是没问题的,

但是毕竟要在公司开发啊,回到公司,果然错误依旧

 

然后找了同事帮我看,看着看着 ,灵机一动 我想起来了,代码不是放在本地,是放在一个共享里,

 

。。。。。。。。。

这个错误的原因来的太纠结了,果然 把代码拷贝到本地,错误也就没了,

真是自己折磨自己啊 

上一篇: 未来农场长这样:无人机、机器人和GPS齐上阵 下一篇: 没有下一篇了!
发表评论
用户名: 匿名