Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi. I am new in both curl and ASP.NET. I am trying to do the curl auth login in ASP.NET.
 
For curl auth login, it will look like this
<pre lang="xml">curl -k https://localhost:8089/services/auth/login \
-d username=admin \
-d password=pass</pre>
 
So in ASP.NET, i try out this:
string url = "https://localhost:8089/services/auth/login";
WebRequest myReq = WebRequest.Create(url);
 
string username = "admin";
string password = "pass";
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(username+"&"+password)));
 
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
 
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Console.WriteLine(content);
Console.ReadLine();
 
However, I am not sure my way in ASP.NET is the correct or vice versa since it gives me a 400 Bad Request.
 
By the way, without
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
 
it will give me underlying SSL connection is not trusty.
 
Hope that someone may know the way to do this right. Thanks!
Posted 22-Oct-12 16:22pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100