问题描述
对于名为 mOTP 的服务,我需要发送一个名为private"的参数.这是我的 Parse 云代码.
For a service called mOTP, I need to send a parameter with name 'private'. Here is my Parse cloud code.
var phnNum = request.params.phnNum;
var validationParams = {"private":"MyPrivateKey"};
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://api.mOTP.in/v1/otp/MyAPIKey/'+MySessionID,
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
params: validationParams,
success: function(httpResponse) {
console.log(httpResponse.data.Status);
console.log(httpResponse.data.Result);
if(phnNum == httpResponse.data.Result) {
response.success("Success");
} else {
response.error("phnNum not matched");
}
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
response.error("URL hit failed");
}
});
mOTP 服务以 JSON 格式提供响应.但我总是收到不支持方法"的回应.我无法找到我做错的地方.请帮忙.mOTP 文档:http://dial2verify.com/mOTP_Missed_Call_OTP_Authentication/Documentation.html
The mOTP service gives response in JSON. But always I am getting the response as 'Method not supported'. I am not able to find where I am doing mistake. Please help.mOTP docs: http://dial2verify.com/mOTP_Missed_Call_OTP_Authentication/Documentation.html
推荐答案
首先,您应该使用 POST 方法传递一个 body 消息.
First of all, You should pass a body message with the POST method.
根据文档,内容类型应为application/x-www-form-urlencoded".
The content-type should be 'application/x-www-form-urlencoded' according to the documentation.
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://motp.p.mashape.com/v1/otp/{APIKey}/{SessionId}',
headers: {
'X-Mashape-Key': 'YOUR-X-Mashape-Key',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: {'private': 'Your_mOTP_Private_Key'},
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error("error: " + httpResponse.status);
}
});
这篇关于在 parse.com 的 post 请求中请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!