Adding Accept multipart/related;type=application/octet-stream to HttpRequestMessage throws error

0
var request = new HttpRequestMessage(HttpMethod.Get, new Uri("http://someurl"));
request.Headers.Add("Accept","multipart/related;type=application/octet-stream");

above code throws below exception

System.FormatException HResult=0x80131537 Message=The format of value 'multipart/related;type=application/octet-stream' is invalid. Source=System.Net.Http StackTrace: at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index) at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(String name, HeaderStoreItemInfo info, String value) at System.Net.Http.Headers.HttpHeaders.Add(String name, String value) at deleteit.Program.Main(String[] args) in c:\users\310227436\source\repos\deleteit\deleteit\Program.cs:line 14

My requirement is I must have to "multipart/related;type=application/octet-stream" as Accept header, as service needs that.

Please help.

c#
http
asp.net-core
.net-core
httpclient
asked on Stack Overflow Jan 30, 2019 by Shankar S

1 Answer

1

HttpClient mostly uses strongly typed headers or tries to validate the input.

Try using:

request.Headers
.TryAddWithoutValidation("Accept","multipart/related;type=application/octet-stream");` 
answered on Stack Overflow Jan 30, 2019 by ste-fu

User contributions licensed under CC BY-SA 3.0