c# - WebRequest GetResponse stuck with default proxy -


i have following code

    private bool isonline()     {         try         {             var wr = webrequest.createhttp("http://www.google.com");             wr.keepalive = false;             wr.credentials = credentialcache.defaultcredentials;             using (wr.getresponse())             {                 return true;             }         }         catch         {             return false;         }     } 

when execute it remains stuck on getresponse line forever.

thanks responses found problem in default proxy. in fact if construct new proxy in following way works

        var registry = registry.currentuser.opensubkey("software\\microsoft\\windows\\currentversion\\internet settings", false);         var proxy = (string)registry.getvalue("proxyserver");         var isproxyenabled = (int)registry.getvalue("proxyenable");          if (isproxyenabled > 0)         {             wr.proxy = new webproxy(proxy, true, null, system.net.credentialcache.defaultnetworkcredentials);         } 

the problem workaround code read registry proxy manually set. doesn't works if user have choose "automatically detect settings".

so: - how can found proxy address in case? - why default proxy not work?

it seems bug in webproxy auto-detection.

by way found more elegant workaround allows me use initial code. after reading this , this questions have put code in app.config file

<system.net>   <defaultproxy enabled="true" usedefaultcredentials="true" >       <proxy autodetect="true" scriptlocation="http://wpad/wpad.dat"/>   </defaultproxy> </system.net> 

this allows program skip internet option settings , go staight check wpad (similarly firefox does)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -