【发布时间】:2019-12-10 21:38:26
【问题描述】:
我正在尝试通过使用的示例服务(即 TripPin)从 OData RESTful API 发布数据。 请求成功,但响应为空。为了发出 HTTP 发布请求,AWS Lambda 平台中是否需要遵守任何特定的结构?
var querystring = require('querystring');
var http = require('http');
exports.handler = function (event, context) {
var post_data = querystring.stringify(
{
UserName:'lewisblack',
FirstName:'Lewis',
LastName:'Black',
Emails:[
'lewisblack@example.com'
],
AddressInfo:[
{
Address: '187 Suffolk Ln.',
City: {
CountryRegion: 'United States',
Name: 'Boise',
Region: 'ID'
}
}
],
Gender: 'Male'
}
);
// An object of options to indicate where to post to
var post_options = {
host: event.url,
port: '80',
path: event.path,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data)
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
console.log("hello");
context.succeed();
});
res.on('error', function (e) {
console.log("Got error: " + e.message);
context.done(null, 'FAILURE');
});
});
// post the data
post_req.write(post_data);
post_req.end();
}
调用参数示例:
{
"url": "services.odata.org",
"path": "/v4/TripPinServiceRW/"
}
回应: 空
请求 ID: "6f1ec2b4-5195-477f-9fb8-56fd33dee0ce"
功能日志: 开始请求 ID:6f1ec2b4-5195-477f-9fb8-56fd33dee0ce 版本:$LATEST
END RequestId:6f1ec2b4-5195-477fenter code here-9fb8-56fd33dee0ce
报告请求 ID:6f1ec2b4-5195-477f-9fb8-56fd33dee0ce 持续时间:431.87 毫秒
计费持续时间:500 毫秒内存大小:128 MB 使用的最大内存:73 MB
【问题讨论】:
标签: node.js amazon-web-services aws-lambda odata