我需要通过Rest API从一个解析应用程序的云中调用另一个解析应用程序中的云调用。
为此,我现在有以下代码。但是,我总是得到这样的错误: com.parse.ParseException: ReferenceError: XMLHttpRequest不是在main.js:12:20中定义的。(这一行引用了初始化XMLHttpRequest的那一行)。我的代码是:
var url = "https://api.parse.com/1/functions/signUp";
var myObj = new Object();
myObj.age = 45;
myObj.email = "test@gmail.com";
myObj.password = "testpw";
var client = new XMLHttpRequest();
client.open("POST", url);
client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
client.setRequestHeader("X-Parse-Application-Id", "xxx");
client.setRequestHeader("X-Parse-REST-API-Key", "xxx");
client.send(JSON.stringify(myObj));因为这段代码是在解析云中执行的,所以我认为问题在于XMLHttpRequest没有正确构造。会是这样吗?
使用Parse,通过来自云的rest-api从另一个解析应用调用云调用,这是可能的吗?
发布于 2014-08-02 04:50:28
您可以使用Parse.Cloud.httpRequest()进行http调用
Parse.Cloud.httpRequest({
url: 'https://api.parse.com/...',
headers: {
'Content-Type':'application/json',
'X-Parse-Application-Id':'...',
'X-Parse-REST-API-Key':'...'
},
method: 'POST',
body: JSON.stringify(myObj)
}).then(function(response) {
console.log(response);
}, function(err) {
console.log(err);
});试试看。回复:https://parse.com/docs/cloud_code_guide#networking
您可以跳过JSON stringify,直接传入myObj。
https://stackoverflow.com/questions/25087949
复制相似问题