An exception occurred during a WebClient request, occurredwebclient
System. Net. WebException was caught
Hresults =-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: \ Help Page and Automatic Message format (JSONXML) Select \ Client \ Program. cs: line 62
InnerException: System. Configuration. ConfigurationErrorsException
Hresults =-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_internaldefawebwebproxy ()
At System. Net. HttpWebRequest.. ctor (Uri uri, ServicePoint servicePoint)
At System. Net. HttpRequestCreator. Create (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
Hresults =-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 (defaproproxysection)
At System. Net. Configuration. DefaultProxySectionInternal. GetSection ()
InnerException:
The above error comes from the following code:
WebClient webClient = new WebClient(); var stream = webClient.OpenRead("http://www.cnblogs.com/"); using (StreamReader reader = new StreamReader(stream)) { Console.WriteLine(reader.ReadToEnd()); }
The above error has made me struggle for a long time. It is just a simple webclient request. How can this problem be solved ??
Baidu has a solution?
Http://codebender.denniland.com/system-net-webexception-an-exception-occurred-during-a-webclient-request/
I tried it, but I still couldn't. I saw the system.net/defaultProxy keyword and thought it was a company network problem. So I tried the network at home after work,
The Code has passed, so I suspect it is okay,
But after all, if I want to develop at the company and return to the company, the error still persists.
Then I found a colleague to help me. I looked at it and thought about it. The code was not put locally, but shared,
.........
The cause of this error is too tangled. I copied the code to the local machine, and the error was gone,
I am suffering myself!