Reputation: 290
In my web Admin, i have to integrate the Parse.com push notification to send the push notifications to subscribers.
My question is
Do i need to integrate REST APIs with curl in my asp.net admin? or there is any other standard C# SDK to implement?
If answer is REST Api then documentation for integrating with the REST api has following example.
curl -X POST \
-H "X-Parse-Application-Id: " \
-H "X-Parse-REST-API-Key: " \
-H "Content-Type: application/json" \
-d '{"score":1337}' \
I have started to integrate the REST API by setting up a test console application to test the urls. The application i developed has following code.
class Program
{
private const string URL = "https://api.parse.com/1/classes/GameScore";
private const string DATA = @"{""score"":1337";
static void Main(string[] args)
{
Program.CreateObject();
Console.ReadLine();
}
private static void CreateObject()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("X-Parse-Application-Id", "My Application ID given in example");
request.Headers.Add("X-Parse-REST-API-Key", "the api key given in example");
request.ContentLength = DATA.Length;
StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
requestWriter.Write(DATA);
requestWriter.Close();
try
{
WebResponse webResponse = request.GetResponse();
Stream webStream = webResponse.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
Console.Out.WriteLine(response);
responseReader.Close();
}
catch (Exception e)
{
Console.Out.WriteLine("-----------------");
Console.Out.WriteLine(e.Message);
}
}
}
The code gives a 400 Bad request error
I don't understand what i am missing.
Thanks in advance
Upvotes: 0
Views: 248