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

使用Flurl在C#中发起Post请求遇阻,请求协助排查

用Flurl发起Post请求时遇到WaitingForActivation状态的问题

自昨日起,我尝试在C#中用Flurl调用API发起Post请求,但Post代码块始终未执行,无法定位问题。持续收到错误信息:

Id = 17, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}"

以下是我的代码:

public async Task<GetCustomerAcctsDetail_Model> GetCustomerAcctsDetail(string num_compte)
{
    try
    {
        //getting fcub endpoint
        var customerdetail_api = Configuration.GetValue<string>("APIs:accountdetails");
        var api_key = Configuration.GetValue<string>("APIs:Authorisation_key");

        var customer_details=  await customerdetail_api
            .WithHeader("Accept", "application/json")
            .WithHeader("Authorization",api_key)
            .PostJsonAsync(new
            {
                channel_code = "MYCHANELCODE",
                account_no = num_compte
            })
            .ReceiveJson<GetCustomerAcctsDetail_Model>();

        return customer_details;
    }
    catch(Exception Ex)
    {
        _logger.LogError(Ex.Message);
        return null;
    }
}

排查建议

  • 检查异步方法的调用方式:这个错误大概率是调用GetCustomerAcctsDetail时未使用await关键字,导致任务仅被创建但未触发执行,处于等待激活状态。必须确保调用代码是var result = await GetCustomerAcctsDetail("你的账号");。
  • 验证API配置有效性:确认APIs:accountdetails配置的URL完整且可访问,APIs:Authorisation_key的格式符合接口要求(比如部分接口需要在密钥前添加Bearer 前缀)。
  • 完善日志信息:在catch块中记录完整异常栈(Ex.ToString()),而不只是错误消息;同时在请求前后添加日志,确认请求是否真正发起,比如:
    _logger.LogInformation("准备调用账户详情API,账号:{NumCompte}", num_compte);
    // 执行Flurl请求代码
    _logger.LogInformation("账户详情API调用完成");
    
  • 直接测试API端点:用Postman或curl工具,传入相同的请求体和请求头,直接调用目标API,确认接口本身是否正常响应,排除服务端问题。
  • 检查Flurl版本:确保使用的Flurl及Flurl.Http包是最新稳定版,旧版本可能存在异步处理的兼容性问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 08:55:17