C# Siteminder Authentication -
i trying write code connect https site uses siteminder authentication.
i keep getting 401. ideas?
i have read few different things on here none have seemed helpful. using fiddler/firefox tamper snoop what's going on.
here i've got far in regards code:
try { uri uri = new uri("https://websiteaddresshere"); httpwebrequest request = (httpwebrequest)webrequest.create(uri) httpwebrequest; request.accept = "text/html, application/xhtml+xml, */*"; request.useragent = "mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) gecko"; // request.connection = "keep-alive"; // request.method = "get"; // request.accept = "text"; request.allowautoredirect = true; request.automaticdecompression = decompressionmethods.gzip | decompressionmethods.deflate; cookie emersoncookie = new cookie("smchallenge", "yes"); emersoncookie.domain = "mydomain"; emersoncookie.path = "/"; // authentication var cache = new credentialcache(); cache.add(uri, "false", new networkcredential("myusername", "mypassword")); request.credentials = cache; // response. using (httpwebresponse response = (httpwebresponse)request.getresponse()) { using (stream stream = response.getresponsestream()) { xmltextreader reader = new xmltextreader(stream); messagebox.show(stream.tostring()); } } } catch (webexception exception) { string responsetext; using (var reader = new streamreader(exception.response.getresponsestream())) { responsetext = reader.readtoend(); messagebox.show(responsetext.tostring()); } }
after doing more reading on msdn website decided go different route.
i ended making service since need service @ end of day , did following:
cookiecontainer emersoncookie = new cookiecontainer(); httpwebrequest request = (httpwebrequest) webrequest.create("https://websiteaddress"); request.credentials = new networkcredential("username", "password"); request.cookiecontainer = emersoncookie; request.method = "get"; httpwebresponse response = (httpwebresponse) request.getresponse(); stream resstream = response.getresponsestream(); using (stream output = file.openwrite(@"c:\\somefolder\\somefile.someextention")) using (stream input = resstream) { input.copyto(output); }
to might running siteminder authentication issues, piece of code works pretty well.
Comments
Post a Comment