使用 Parse.Cloud.httpRequest 我无法为 AWS 请求设置正确的 header?

using Parse.Cloud.httpRequest I am unable to set correct header for AWS request?

在 Parse.com,我需要从 CloudCode 向 AWS (Kinesis) 发送 httpRequest;它们已签名,并且在从浏览器端(扩展)发送时一切正常。我在 CloudCode 的请求中尝试了以下 header content-type:

"content-type": "application/json"

AWS refused it: {"Output":{"__type":"com.amazon.coral.service#UnknownOperationException","message":null},"Version":"1.0"}

"content-type": "application/x-amz-json-1.1"

parse.cloud.httprequest refused it: Result: Uncaught Error: Don't know how to convert httpRequest body Object to application/x-amz-json-1.1. To send raw bytes, please assign httpRequest body to a Buffer object containing your data.

"content-type": "application/x-www-form-urlencoded"

AWS refused it: Request failed with response code 403

AWS 文档到处都提到了 "application/x-amz-json-1.1" content-type,我看不到任何替代方案。所以,我假设这是要走的路,所以:

如何让 Parse.Cloud.httpRequest 发送带有此 X-AMZ-JSON header 的请求,但使用 "application/json" “内部”?

更新:我尝试使用从 Node 获取的 "http" 和 "xmlhttp" 模块;但其中 none 有效——我很乐意尝试您提出的任何建议。

更新:这是我提出的实际要求

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+'\'}' });                       
  }
});                                                             

查看有关通过 httpRequest 发送原始字节的博客 post:http://blog.parse.com/2013/04/04/sending-bytes-from-cloud-code/

如果http_req_body是一个JS对象,那么可以使用下面的方法调用:

// Require can go at the global scope
var Buffer = require('buffer').Buffer;
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: new Buffer(JSON.stringify(http_req_body))
}).always(function(httpResponse) {
  var message = httpResponse.text;
  res.render('json', {message: '{response:\''+message+'\'}' });                       
});

我还冒昧地将您的 success/error 回调替换为较新的 Promise 技术 (http://blog.parse.com/2013/01/29/whats-so-great-about-javascript-promises/)。这不仅可以让您更轻松地管理多个 API 请求,还可以让您合并为成功和错误条件重写的处理程序。