c# - HttpWebRequest using Basic authentication -


i'm trying go through authentication request mimics "basic auth request" we're used seeing when setting iis behavior.

the url is: https://telematicoprova.agenziadogane.it/telematicoservizidiutilitaweb/servizidiutilitaautservlet?uc=22&sc=1&st=2
(warning: https!)

this server running under unix , java application server.

this code use connect server:

cookiecontainer mycontainer = new cookiecontainer(); httpwebrequest request = (httpwebrequest)webrequest.create("https://telematicoprova.agenziadogane.it/telematicoservizidiutilitaweb/servizidiutilitaautservlet?uc=22&sc=1&st=2"); request.credentials = new networkcredential(xxx,xxx); request.cookiecontainer = mycontainer; request.preauthenticate = true; httpwebresponse response = (httpwebresponse)request.getresponse(); 

(i copied post on site). receive answer server:

the underlying connection closed: unexpected error occurred on send.

i think tried every possible task knowledge on c# has offer me, nothing...

you can add authorization header yourself.

just make name "authorization" , value "basic base64({username:password})"

string username = "abc"; string password = "123"; string encoded = system.convert.tobase64string(system.text.encoding.getencoding("iso-8859-1").getbytes(username + ":" + password)); httpwebrequest.headers.add("authorization", "basic " + encoded); 

edit

switched encoding utf-8 iso 8859-1 per what encoding should use http basic authentication? , jeroen's comment.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -