I am trying to send the HTTP post
request using HTTP client
.while setting my Content-Type
header with StringContent
method, I am getting the error:
the format "application/json;ty=2 "is incorrect
My code is as follows:
string result2 = JsonConvert.SerializeObject(values);
var content = new StringContent(result2, Encoding.UTF8, "application/json; ty=2");
var response = await client.PostAsync("http://127.0.0.1:8080/~/in-cse/in-name", content);
var response_string = await response.Content.ReadAsStringAsync();
But in my HTTP Post format I have to include ty=2
parameter along with application/json
. I have tested this with Postman
and it worked perfectly. How can I achieve the same thing here. I also even found you can add parameter to content type in the following format:
content := "Content-Type" ":" type "/" subtype *(";" parameter)
then why is it not working for me.
**EDIT:**even tried this:
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://127.0.0.1:8080/~/in-cse/in-name");
request.Content = new StringContent(result2, Encoding.UTF8, "application/json;ty=2");
client.SendAsync(request).ContinueWith(resposetask => { Console.WriteLine("response:{0}", resposetask.Result); });
same error i am getting