Click here to Skip to main content
13,043,865 members (47,599 online)
Rate this:
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();

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 15:22pm

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2017
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