(415) Unsupported Media Type

Posted on 2012-09-02
Last Modified: 2013-11-19
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);

            WebResponse response = myRequest.GetResponse();
Question by:perlwhite
    LVL 26

    Assisted Solution

    by:Alan Warren
    You may need to use myRequest.ContentType = "multipart/form-data; boundary=";

    HTTP POST request issue

    LVL 16

    Assisted Solution

    by:Easwaran Paramasivam
    Content-Type: application/json could be used. Please check it out:

    Author Comment

    Thank you both, however either of the solutions did not work. I get the same runtime error.
    LVL 26

    Accepted Solution

    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:

    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:

    You should check that your configuration is correct -- this is a nice explanation of an error in configuring the server:

    And finally, this is a nice verbose discussion of 415 that you might find educational:

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now