Proxy Basic Authentication in C#: HTTP 407 error -


i working proxy requires authentication, i.e., in browser if try open page ask credentials. supplied same credentials in program fails http 407 error.

here code:

httpwebrequest request = (httpwebrequest)webrequest.create(url);  iwebproxy proxy = webrequest.getsystemwebproxy(); credentialcache cc = new credentialcache(); networkcredential nc = new networkcredential();  nc.username = "username"; nc.password = "password"; nc.domain = "mydomain"; cc.add("http://20.154.23.100", 8888, "basic", nc); proxy.credentials = cc; //proxy.credentials = system.net.credentialcache.defaultcredentials; request.proxy = proxy; request.proxy.credentials = cc; request.credentials = cc; request.preauthenticate = true; 

i have tried every possible thing seem missing something. like, have make 2 requests? first out credentials , once hear server need credentials, make same request credentials?

this method may avoid need hard code or configure proxy credentials, may desirable.

put in application configuration file - app.config. visual studio rename yourappname.exe.config on build, , end next executable. if don't have application configuration file, add 1 using add new item in visual studio.

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <system.net>     <defaultproxy usedefaultcredentials="true" />   </system.net> </configuration> 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -