ContentType for HttpClient request
See original GitHub issuehow to setup contentType for HttpClient request?
val client = HttpClient(OkHttp) {
engine {
defaultRequest {
contentType(ContentType.Application.FormUrlEncoded)
}
}
}
this code throws exception:
io.ktor.http.UnsafeHeaderException: Header Content-Type is controlled by the engine and cannot be set explicitly
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:9 (5 by maintainers)
Top Results From Across the Web
How do you set the Content-Type header for an HttpClient ...
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://example.com/"); httpClient.DefaultRequestHeaders.Add("Accept", ...
Read more >How to set the Content-Type header for an HttpClient request
How to set the Content-Type header for an HttpClient request · var client = new HttpClient(); · client.BaseAddress = new Uri("http://example.com/"); · //...
Read more >HttpClient and how to use Headers, Content-Type and ...
Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects."
Read more >C# HttpClient - How to set the HTTP Content-Type header
This post describes how to make a HTTP request with a specific content-type for example "text/plain" using the HttpClient in C#.
Read more >How to set the Content-Type header for an HttpClient request ...
The code for How to set the Content-Type header for an HttpClient request? HttpClient client = new HttpClient(); client.BaseAddress = new Uri ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure 😃
@e5l What if you don’t want to specify a
Content-Type
? There’s this scenario with direct uploads to Google Cloud Storage Buckets where adding aContent-Type
header results in a signature mismatch. Here’s more info about this.The following also fails because it sets
Content-Type: null
: