无法通过Flurl错误411长度发布POST附件

时间:2018-09-17 21:00:15

标签: c# post flurl

有人可以在这里解释我在做什么错吗?我正在指定长度标题。不知道为什么说“需要长度”。当我通过Postman发送此请求时,该请求工作正常,但当我通过C#中的Flurl发送时,该请求失败。这是通话的API docs

  

上传附件时出错:Flurl.Http.FlurlHttpException:POST https://xxx.leankit.com/kanban/api/card/SaveAttachment/365784226/733054060失败,状态码为411(需要长度)。\ r \ n响应正文:错误的请求\ n您的浏览器发送了该服务器无法理解的请求。

上传文件代码

public static async Task<string> UploadFile(string externalcardid, string filePath,string filename,int boardId,long size)
{
    try
    {
        var url = "https://xxx.leankit.com/kanban/api/card/SaveAttachment/" + boardId + "/" + externalcardid.ToString();
        var responseString = await url.WithBasicAuth("xxx", "yyy")
            .WithHeader("Content-Length", size)
            .WithHeader("Content-Type", "multipart/form-data")
            .PostMultipartAsync(mp=> mp
                .AddFile(filename,filePath)
            )
      .ReceiveString();
        return (responseString);
    }
    catch (Exception e)
    {
        return ("Error uploading attachment: " + e);
    }
}

enter image description here

0 个答案:

没有答案