【发布时间】:2015-02-18 11:15:01
【问题描述】:
在 Parse.com 上,我需要从 CloudCode 向 AWS (Kinesis) 发送 httpRequest;它们已签名,并且从浏览器端(扩展)发送时一切正常。我在 CloudCode 中的请求中尝试了以下标头内容类型:
"content-type": "application/json"
AWS 拒绝它:{"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}
"content-type": "application/x-amz-json-1.1"
parse.cloud.httprequest 拒绝它:结果:未捕获错误:不知道如何将 httpRequest 正文对象转换为 application/x-amz-json-1.1。要发送原始字节,请将 httpRequest 正文分配给包含您的数据的 Buffer 对象。
"content-type": "application/x-www-form-urlencoded"
AWS 拒绝:请求失败,响应代码为 403
AWS 文档到处都提到了“application/x-amz-json-1.1”内容类型,我看不到任何替代方案。所以,我假设这是要走的路,所以:
如何让 Parse.Cloud.httpRequest 发送带有此 X-AMZ-JSON 标头的请求,但在“内部”使用“application/json”?
更新:我尝试使用取自 Node 的“http”和“xmlhttp”模块;但它们都不起作用——我很乐意尝试您提出的任何建议。
更新:这是我提出的实际要求
Parse.Cloud.httpRequest({
method: 'POST',
url: awsKinesisUrl,
headers: {
"Authorization": concat_string,
"action": "PutRecord",
"acl": "public-read",
'awsaccesskeyid': "__XXX__",
"content-type": "application/x-amz-json-1.1",
"dategenerated": date_generated+"",
"region": "eu-west-1",
"version": "2013-12-02",
"X-Amz-Date": date_generated_TZ+"",
"X-Amz-Target": "Kinesis_20131202.PutRecords"
},
body: {
body: http_req_body
},
success: function(httpResponse) {
var message = httpResponse.text;
res.render('json', {message: '{response:\''+message+'\'}' });
},
error: function(httpResponse) {
var message = httpResponse.status;
res.render('json', {message: '{response:\''+message+'\'}' });
}
});
【问题讨论】:
标签: json amazon-web-services parse-platform header httprequest