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
Post a Comment