android - ParseCloud httpRequest post exception -
i trying execute http request in using cloud code module parse.com. invoke android app keep getting exception :
com.parse.parseexception:java.lang.illegalargumentexception trying execute post command without body parameters.
code below , keeps giving me
parse.cloud.define('httprequest', function(request, response) { var requestparams = { 'apikey': '{api_key}', 'currency':'gbp', 'locale':'en-gb', 'adults':'1', 'children':'0', 'infants':'0', 'originplace':'11235', 'destinationplace':'13554', 'outbounddate':'2015-08-19', 'inbounddate':'2015-08-26', 'locationschema':'default', 'cabinclass':'economy', 'grouppricing':'true', 'country':'gb' }; parse.cloud.httprequest({ method: 'post', url: 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/', headers: { 'content-type': 'application/x-www-form-urlencoded', }, body: {'private': 'your_motp_private_key'}, params: requestparams, success: function(httpresponse) { response.success(httpresponse.text); console.log(httpresponse.text); }, error: function(httpresponse) { response.error("error: " + httpresponse.status); console.log(httpresponse.status); } }); }); parse.initialize(this,"{app_id}","{client_key}"); parsecloud.callfunctioninbackground("httprequest", null, new functioncallback<map<string, object>>() { public void done(map<string, object> mapobject, parseexception e) { if (e == null) { toast.maketext(mainactivity.this, mapobject.tostring(), toast.length_long).show(); }else{ toast.maketext(mainactivity.this,e.getmessage(),toast.length_long).show(); log.i(e.getmessage()); } } });
i had got problem. solved.
callfunctioninbackground 's 2nd parameter cannot null.
here's example
map<string, string> parameters = new hashmap<string, string>(); parsecloud.callfunctioninbackground("onphotoupload", parameters, new functioncallback<hashmap<string, string>>() { public void done(hashmap<string, string> mapobject, parseexception e) { if (e == null) { toast.maketext(context, mapobject.get("answer").tostring(), toast.length_short).show(); } else { log.e("onphotoupload", e.getmessage()); toast.maketext(context, "error saving: " + e.getmessage(), toast.length_short).show(); } } });
Comments
Post a Comment