asp.net - How do I send API credentials and username / password with .Net / Parse.com? (PHP to C#) -
i trying create web page allow users login , view data. data hosted on parse.com exposes rest api.
i using asp.net / c# access , can using api key , application key. however, need write version of php code documentation in c#...
to this, send request /1/login endpoint username , password url-encoded parameters:
curl -x \ -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 stuck here...anything have tried returns http 400, such 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 c# code gets me data...but want data user trying 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 / pointers appreciated. thanks!
i see 2 things wrong first code sample. first, need pass credentials headers, not using http authentication.
httpwebrequest.headers.add("x-parse-application-id", applicationid); httpwebrequest.headers.add("x-parse-rest-api-key", apikey);
second, need pass parameters in data call, not headers. going need create string url-encoded data in ("username=the_username&password=a%30password") , write request stream.
Comments
Post a Comment