我正在尝试使用Parse.com中的云代码模块执行http请求。然后我从我的Android应用程序调用,但一直得到这个例外:
com.parse.ParseException:java.lang.IllegalArgumentException
尝试执行没有正文参数的POST命令。
下面的代码,它不断给我
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());
}
}
});
答案 0 :(得分:2)
我也有这个问题。然后我解决了。
callFunctionInBackground的第二个参数不能为空。
这是示例
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();
}
}
});