I am trying to create a web page that will allow my users to login and view their data. The data is hosted on Parse.com which exposes it as a REST API.
I am using asp.net / C# to access it and can get it all by using their API Key and Application Key. However, I need to write a version of this PHP code from their documentation in C#...
To do this, send a GET request to the /1/login endpoint with username and password as URL-encoded parameters:
curl -X GET \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-G \
--data-urlencode 'username=cooldude6' \
--data-urlencode 'password=p_n7!-e8' \
https://api.parse.com/1/login
Now I am stuck here...anything that I have tried returns an HTTP 400, such as this code...
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string ParseAuthenticate(string strUserName, string strPassword )
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.parse.com/1/login");
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Headers.Add("username:" + strUserName);
httpWebRequest.Headers.Add("password:" + strPassword);
//pass basic authentication credentials
httpWebRequest.Credentials = new NetworkCredential("My Parse Application Id", "Parse API Rest Key");
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
return responseText;
}
}
Here is my C# code that gets me all the data...but I only want data for the user that is trying to login...
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetParseData()
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.parse.com/1/classes/Visit");
//pass basic authentication credentials
httpWebRequest.Credentials = new NetworkCredential("My Parse Application Id", "My Parse REST API Key");
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
return responseText;
}
}
Any help / pointers will be greatly appreciated. Thanks!