【发布时间】:2022-01-31 06:50:11
【问题描述】:
我正在使用 Postman 来测试 Azure Function。对于这段代码
context.res = {status: 200, body: "ok", txt: "hello"};
【问题讨论】:
标签: javascript azure-functions postman
我正在使用 Postman 来测试 Azure Function。对于这段代码
context.res = {status: 200, body: "ok", txt: "hello"};
【问题讨论】:
标签: javascript azure-functions postman
根据Azure Functions JavaScript developer guide,响应不包含您指定的对象:
context.res(响应)对象具有以下属性:
Property Description body An object that contains the body of the response. headers An object that contains the response headers. isRaw Indicates that formatting is skipped for the response. status The HTTP status code of the response. cookies An array of HTTP cookie objects that are set in the response. An >HTTP cookie object has a name,value, and other cookie properties, such as >maxAgeorsameSite.
我假设属性 txt 没有序列化到响应,所以我认为您不能从邮递员或其他任何其他客户端访问它。
如果你想返回一些数据你应该把它添加到body:
context.res = {
status: 200,
body: {
"message": "ok",
"txt": "hello"
}
};
【讨论】: