简体   繁体   English

如何通过解析云代码中的作业创建httpRequest?

[英]How to make an httpRequest from jobs in parse cloud code?

Parse.Cloud.job("syncMetadataWithContentPortal", function(request, status) {
    var apikey ="49eiivmz"; 
    var uid = "t1g4Y2jC6S";
    Parse.Cloud.httpRequest({
        url: 'https://api.parse.com/1/functions/getContentMetaData',
        method: 'GET',    
        headers : { 
            'Content-Type': 'application/json',
            'X-Parse-Application-Id':'appkey',
            'X-Parse-REST-API-Key':'restapikey',  
        },
        body: {
            apiKey : apikey
        }
    }).then(function(httpResponse) {
        Parse.Cloud.useMasterKey();
        status.message(httpResponse.text);
        console.log(httpResponse.text);
        var contents = JSON.parse(httpResponse.text);

        var contentIdCollection = [];
        for (var i = 0; i < contents.length; i++) {
            contentIdCollection.push(contents[i].id);
        }
        status.success('Content Synced');
    }, function(httpResponse) {
        // console.error('Request failed with response code ' + httpResponse.status);
        status.error('Request failed with response code ' + httpResponse.status)
    });
});

So I have a job making httpRequest to call a function getContentMetaData which requires API key as a parameter. 因此,我有一项工作使httpRequest调用需要API键作为参数的getContentMetaData函数。

  1. How do I send parameters using GET method? 如何使用GET方法发送参数?
  2. I got status as :Request failed with response code 405 我的状态为:请求失败,响应代码为405

Please help me how to solve this. 请帮我解决这个问题。 Thanks in advance. 提前致谢。

Don't use Parse.Cloud.httpRequest to call other cloud functions, instead you should be using Parse.Cloud.run 不要使用Parse.Cloud.httpRequest调用其他云函数,而应该使用Parse.Cloud.run

Your problem could also be related to your headers as you appear to be using string literals instead of variable references. 您的问题也可能与标头有关,因为您似乎在使用字符串文字而不是变量引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM