You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Durable Functions Http Trigger触发请求体读取超时问题求解

根因说明

你的HttpStart函数默认从POST请求的Body中读取JSON格式的输入参数,但你发起请求时仅把路径参数放在了URL的查询串中,没有携带任何请求Body,服务端等待接收请求Body超时,触发了Kestrel的最小请求体数据速率限制报错。

解决方案

方案一:调整Postman请求(无需修改代码)

  • 在Postman的请求配置页切换到Body标签,选择raw格式,右侧格式下拉选择JSON
  • 在Body输入框中填入你的目标路径,示例内容如下:
"D:\\Tmp"
  • 删除URL末尾的?req="D:\Tmp"查询参数,重新发起请求即可正常触发函数。

方案二:修改代码兼容URL传参

如果需要保留通过URL查询参数传参的使用方式,可以修改HttpStart的逻辑,兼容两种传参方式,修改后的代码参考:

import logging
import json
import azure.functions as func
import azure.durable_functions as df

async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
    client = df.DurableOrchestrationClient(starter)
    payload = None
    # 优先读取请求Body中的JSON参数
    try:
        req_body = req.get_body().decode()
        if req_body:
            payload = json.loads(req_body)
    except:
        pass
    # Body为空时读取URL查询参数中的req字段
    if not payload:
        payload = req.params.get('req')
    if not payload:
        return func.HttpResponse(
            "请通过POST Body传入路径参数,或在URL中添加req查询参数",
            status_code=400
        )
    instance_id = await client.start_new(req.route_params["functionName"], client_input=payload)
    logging.info(f"Started orchestration with ID = '{instance_id}'.")
    return client.create_check_status_response(req, instance_id)

内容的提问来源于stack exchange,提问作者SiG Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 22:27:01