我使用亚马逊API网关搭建了一个API,并且想要将数据放入Kinesis流中。亚马逊API网关有内置的支持。但是当我尝试输入JSON数据时,它会给出“序列化异常”的错误信息。
var data = {"ua_platform":"iPhone","ua_browsercodename":"Mozilla","ua_browserlanguage":"en-us","ua_header":"Mozilla\/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit\/601.1.46 (KHTML, like Gecko) Version\/9.0 Mobile\/13B143 Safari\/601.1","ua_browsername":"Netscape","key":"livestream_hindi",,"datetime_ut":"1458711871","datetime_dt":"2016-03-23","value":"15","source":"0","browser":"Mobile Safari-9.0.","os":"iOS-9.1.","device_detail":"iPhone Apple iPhone"};
var json = JSON.stringify(data);
var params = {
'ContentType': 'application/json',
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'
};
var body = {
"Data": json,
"StreamName": "XXXXXX",
"PartitionKey": "XXXX"
};
接着,我进行了一个PUT请求。
apigClient.functionPut(params, body, additionalParams)
.then(function(result) {
// This is where you would put a success callback
console.log("success");
})
.catch(function(result) {
// This is where you would put an error callback
console.log("catch");
});
API返回200 ok,同时还有序列化异常。在put请求中,变量体的"Data"键只接受"blob"类型。我也尝试将JSON数据转换为BLOB,但没有成功。
我无法找出自己到底做错了什么。请帮忙查看一下。