parse.com中的发布请求中的请求参数 [英] Request parameters in a post request in parse.com

查看:75
本文介绍了parse.com中的发布请求中的请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于名为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中的发布请求中的请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆