How to change the HTTP Request Content Type for FLURL Client?

前端 未结 5 1863
小鲜肉
小鲜肉 2021-01-18 10:39

I am using flurl to submit HTTP request and this is very useful. Now I need to change the \"Content-Type\" header for some of the requests to \"appl

5条回答
  •  礼貌的吻别
    2021-01-18 11:05

    Am I allowed to post 3 answers to the same question? :)

    Upgrade. Flurl.Http 2.0 includes the following enhancements to headers:

    1. WithHeader(s) now uses TryAddWithoutValidation under the hood. With that change alone, the OP's code will work as originally posted.

    2. Headers are now set at the request level, which solves another known issue.

    3. When using SetHeaders with object notation, underscores in property names will be converted to hyphens in the header names, since hyphens in headers are very common, underscores are not, and hyphens are not allowed in C# identifiers.

    This will be useful in your case:

    .WithHeaders(new {
        x_ms_version = "2.11",
        Accept = "application/json"
    });
    

提交回复
热议问题