【问题标题】:How to see non-body returns?如何查看非实体回报?
【发布时间】:2022-01-31 06:50:11
【问题描述】:

我正在使用 Postman 来测试 Azure Function。对于这段代码

context.res = {status: 200, body: "ok", txt: "hello"};

txt 无处可见。无论如何要检查它还是必须将其包装在body 下?

【问题讨论】:

    标签: javascript azure-functions postman


    【解决方案1】:

    根据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 >maxAge or sameSite.

    我假设属性 txt 没有序列化到响应,所以我认为您不能从邮递员或其他任何其他客户端访问它。

    如果你想返回一些数据你应该把它添加到body:

    context.res = {
        status: 200, 
        body: {
            "message": "ok", 
            "txt": "hello"
        }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-24
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多