Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
meteor应用程序中的HTTP post错误_Http_Meteor - Fatal编程技术网

meteor应用程序中的HTTP post错误

meteor应用程序中的HTTP post错误,http,meteor,Http,Meteor,我正在尝试使用以下代码通过meteor调用HTTP post api: HTTP.post(url, { headers: { 'X-Parse-Application-Id': appID, 'X-Parse-REST-API-Key': restKey, 'content-type': 'applicat

我正在尝试使用以下代码通过meteor调用HTTP post api:

   HTTP.post(url, {
                    headers: {
                        'X-Parse-Application-Id': appID,
                        'X-Parse-REST-API-Key': restKey,
                        'content-type': 'application/json'
                    },
                    data: {
                        "username": username,
                        "password": password,
                        "usertype": "3"

                    }
                }, function(error, result) { 
                    if (error) {
                        console.log(error);
                    } 
                }

            );
此代码给出HTTP错误:

{
    "code": 200,
    "error": "bad or missing username"
}
我已经在google chrome中使用Postman扩展测试了HTTP post请求,并且成功地发布了数据。我在postman中使用了与上述HTTP请求相同的URL和标题,并将主体定义为原始json数据:

{ 
    "username": "testuser123",
    "password": "123456", 
    "usertype": "3"

}
我不知道为什么Meteor HTTP POST请求是一个错误的请求。我可以在Meteor中成功调用HTTP Get API,问题只出现在Post API中。
我正试图通过这个API创建一个新用户。在此之前,此post请求是为了解析。现在,由于迁移,我在Heroku上部署了解析服务器。这个post请求在迁移之前运行得非常好。迁移后,所有GET请求都正常,但此post请求存在问题。

将内容类型从application/json替换为application/x-www-form-urlencoded,并使用params代替数据修复了该问题

 HTTP.call('POST', url, {
                    headers: {
                        'X-Parse-Application-Id': appID,
                        'X-Parse-REST-API-Key': restKey,
                        'content-Type': 'application/x-www-form-urlencoded'
                    },
                    params: {

                        'username': u,
                        'password': p,
                        'usertype' : "3"

                    }
                }, function(error, result) {
                    Session.set("loading",false);
                    if (error) {
                        console.log(error);
                    } 

                }

            );

您是否尝试过使用
params
而不是
data
?此外,在您展示如何准确解析服务器上的请求之前,很难回答您的问题。我怀疑此API不受OP的控制@Deep Arora,你能为你试图发布的API添加一个指向文档的链接吗?我已经添加了调用API所需的其他信息。API后ca的文件可在以下注册部分找到: