Custom header to HttpClient request

前端 未结 4 1732
走了就别回头了
走了就别回头了 2020-11-27 03:38

How do I add a custom header to a HttpClient request? I am using PostAsJsonAsync method to post the JSON. The custom header that I would need to b

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 04:29

    There is a Headers property in the HttpRequestMessage class. You can add custom headers there, which will be sent with each HTTP request. The DefaultRequestHeaders in the HttpClient class, on the other hand, sets headers to be sent with each request sent using that client object, hence the name Default Request Headers.

    Hope this makes things more clear, at least for someone seeing this answer in future.

提交回复
热议问题