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:
上述的错误来自于下面的代码:
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 关键词,以为是公司网络问题,于是下班之后在家里的网络试了一下,
竟然代码通过了,所以我的怀疑是没问题的,
但是毕竟要在公司开发啊,回到公司,果然错误依旧
然后找了同事帮我看,看着看着 ,灵机一动 我想起来了,代码不是放在本地,是放在一个共享里,
。。。。。。。。。
这个错误的原因来的太纠结了,果然 把代码拷贝到本地,错误也就没了,
真是自己折磨自己啊