Answer the question
In order to leave comments, you need to log in
C#. How to fix error 415 Unsupported Media Type?
I started writing applications that interact with various APIs. Requests checked in the browser and in the application. GET requests to one of the servers in the application return a 415 Unsupported Media Type error . Other servers don't have this problem. Chrome gets a response.
On advice from google, I tried to add request.ContentType = "application/json" , but there was no result.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.ContentType = "application/json";
Stream dataStream;
HttpWebResponse WebResponse = (HttpWebResponse)request.GetResponse(); // *(415) Unsupported Media Type.
dataStream = WebResponse.GetResponseStream();
StreamReader StreamReader = new StreamReader(dataStream);
ResponseFromServer = StreamReader.ReadToEnd();
dataStream.Close();
WebResponse.Close();
StatusCode = HttpStatusCode.OK;
Answer the question
In order to leave comments, you need to log in
What are you betting Content-Type
on in a GET request? This header is set by the side that sends the body - either the server, when sending a response with a body, or the client, when sending a request with a body (ie POST or PUT). As Oleg Pogrebnyak
already pointed out , you need an Accept header .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question