gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:27:10 25 4
gpt4 key购买 nike

在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com