• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4791
  • Last Modified:

(415) Unsupported Media Type

I get the (415) Unsupported Media Type error when I use POST in REST. I am using C# and Visual Web developer 2010 Express. I do not control the service. Here is the partial code:

byte[] data = UTF8Encoding.UTF8.GetBytes(postData);

myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;

            Stream newStream = myRequest.GetRequestStream();
           
            newStream.Write(data, 0, data.Length);
            newStream.Close();

            WebResponse response = myRequest.GetResponse();
0
perlwhite
Asked:
perlwhite
3 Solutions
 
Alan WarrenCommented:
You may need to use myRequest.ContentType = "multipart/form-data; boundary=";

HTTP POST request issue

Alan
0
 
Easwaran ParamasivamCommented:
Content-Type: application/json could be used. Please check it out:

http://comments.gmane.org/gmane.comp.db.couchdb.user/9198
0
 
perlwhiteAuthor Commented:
Thank you both, however either of the solutions did not work. I get the same runtime error.
0
 
mrcoffee365Commented:
Several things can cause the 415 HTTP response code.  See this nice summary for descriptions of all the HTTP response codes you are likely to hit using REST:
http://brockallen.com/2012/05/14/http-status-codes-for-rest/

Probably the content type you're requesting is not correct for what is being returned.  To debug, you should turn on tracing for your requests to see what is in the header you are sending.  See this discussion from msdn about the possible causes of the 415 HTTP Response Code:
http://social.msdn.microsoft.com/Forums/is/wcf/thread/bcadd339-662d-4751-b96a-ac09fd297d00

You should check that your configuration is correct -- this is a nice explanation of an error in configuring the server:
http://blogs.msdn.com/b/endpoint/archive/2010/11/01/wcf-webhttp-service-returns-http-415-unsupported-media-type.aspx

And finally, this is a nice verbose discussion of 415 that you might find educational:
http://www.checkupdown.com/status/E415.html
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now