Click here to Skip to main content
11,929,166 members (64,878 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 16: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
Web04 | 2.8.151126.1 | Last Updated 22 Oct 2012
Copyright © CodeProject, 1999-2015
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