node.js - 在POST请求 header 中将Transfer-Encoding设置为分块时,Azure函数(Node.js)返回502错误

标签 node.js azure http-post azure-functions transfer-encoding

在POST请求的标头中设置“ Transfer-Encoding:chunked”时,Azure函数(Node.js)返回502错误。

从POST请求的标头中删除“ Transfer-Encoding:chunked”可以正常工作,并按预期返回200响应。但是,要求是在请求标头中设置“传输编码:分块”。

例:

以下请求无效,并返回502错误:

curl -X POST \
  https://example.azurewebsites.net/api/endpoint \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'accept-encoding: gzip, deflate' \
  -H 'Postman-Token: a6177169-f534-4642-8926-b11230a90d67' \
  -H 'Transfer-Encoding: chunked' \
  -H 'cache-control: no-cache' \
  -d 'param1=abc&param2=def'


而以下请求可以正常工作并返回200响应:

curl -X POST \
  https://example.azurewebsites.net/api/endpoint \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'accept-encoding: gzip, deflate' \
  -H 'Postman-Token: a6177169-f523-4642-8926-b11230a90d23' \
  -H 'cache-control: no-cache' \
  -d 'param1=abc&param2=def'


这是返回的错误消息的一部分:

</style>
    </head>
    <body>
        <div id="header">
            <h1>Server Error</h1>
        </div>
        <div id="content">
            <div class="content-container">
                <fieldset>
                    <h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>
                    <h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3>
                </fieldset>
            </div>
        </div>
    </body>
</html>

最佳答案

也许SO线程In HTTP 502, what is meant by an invalid response?的答案可以帮助解释这个问题。


  如果这是代理收到的响应消息,则该代理务必
  关闭与服务器的连接,丢弃收到的响应,然后
  向客户端发送502(错误网关)响应。


上面的内容来自RFC7230 3.3.3 Message Body LengthHypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing部分的第四项。

有理由相信,Azure Functions通过代理来提供服务,与通过IIS在NodeJ中的Azure WebApp相似。

关于node.js - 在POST请求 header 中将Transfer-Encoding设置为分块时,Azure函数(Node.js)返回502错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57155137/

相关文章:

c# - Windows Phone 8.1 POST x-www-form-urlencoded 不工作

javascript - 使用nodejs访问github存储库

asp.net - 在 ASP.Net 中响应 HTTP Post

javascript - 如何取消设置 iso dateTime 日期格式的时间属性

无 GUI VM 中的 Azure CLI 非交互式登录

node.js - Azure Function 应用程序(V3、nodejs)在 zip 部署后没有任何功能

azure - 从 CircleCI 部署到 Azure

Java - 高效处理文件上传并创建新的http请求

javascript - Async/await 未按预期顺序执行

node.js - Passport-local-mongoose serializeUser 类型不正确