简体   繁体   English

通过解析云代码进行HTTP请求

[英]HTTP request through Parse Cloud code

So I am trying to get the cloud code to do an aftersave event that pings another location to do some data saving. 因此,我试图让云代码执行一次Aftersave事件,以便对另一个位置执行ping操作以保存一些数据。

It has some data that needs to be sent as well. 它也需要发送一些数据。

Parse.Cloud.afterSave("ArtPiece", function(request) {
var artistURL = 'http://www.gallery-admin-dev.iartview.com/Gilmans/imageSave.php';

var pieceName = "Robert Rauschenberg Quote";
var url = 'http://www.gilmancontemporary.com/wp-content/uploads/2015/06/Delicate_Garden.The_Bear.48x42.jpeg';

Parse.Cloud.httpRequest({
    url: artistURL,
    dataType : "text",
    crossDomain: true,
    type:"GET",
    data : {
      pieceName : pieceName,
      url : url
    },

    success: function(httpResponse) {
        response(httpResponse.text);
    },
    error: function(httpResponse) {
        response('Request failed with response code ' + httpResponse.status)
    }
});

});

The code does not give an error, or any warnings. 该代码没有给出错误或任何警告。 Me saving/creating entries works fine. 我保存/创建条目效果很好。

Cors is already handled, as I can successfully make this call with an ajax script. Cors已经处理完毕,因为我可以使用ajax脚本成功进行此调用。

Any clue why this is not sending? 任何线索为什么不发送? Can I not have data in a parse httpRequest? 我可以在解析的httpRequest中没有数据吗? Can it not be crossdomain? 可以不是跨网域吗?

Alternatively Is there a way to test this code outside of the Parse Cloud??? 或者,有没有办法在Parse Cloud之外测试此代码?

The way you call httpRequest function is not correct in cloud. 您在云端调用httpRequest函数的方式不正确。 You also do not need to worry about CORS as you are not working in a browser environment. 您也不必担心CORS,因为您不在浏览器环境中工作。 Try this instead: 尝试以下方法:

Parse.Cloud.httpRequest({
    url: artistURL,
    params: {
      pieceName : pieceName,
      url : url
    },
    success: function(httpResponse) {
        response(httpResponse.text);
    },
    error: function(httpResponse) {
        response('Request failed with response code ' + httpResponse.status)
    }
});

To test this outside cloud environment you can use the curl command. 要测试此外部云环境,可以使用curl命令。 It will be something like: 它将类似于:

curl -G -v "http://www.gallery-admin-dev.iartview.com/Gilmans/imageSave.php" --data-urlencode "pieceName=Robert Rauschenberg Quote,url=http://www.gilmancontemporary.com/wp-content/uploads/2015/06/Delicate_Garden.The_Bear.48x42.jpeg"

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

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