Home > Java > javaTutorial > body text

Why Do I Get an HTTP 415 Unsupported Media Type Error When Sending a JSON Request?

Barbara Streisand
Release: 2024-11-06 15:05:02
Original
840 people have browsed it

Why Do I Get an HTTP 415 Unsupported Media Type Error When Sending a JSON Request?

HTTP 415 Unsupported Media Type with JSON Request

When sending a JSON request to a REST API, you may encounter an "Unsupported Media Type" (HTTP 415) error. This typically indicates that the server is expecting a different content type for the request's body.

In the example provided, the problem stems from specifying "charset=utf8" in the Content-Type header. The server is likely configured to accept JSON requests with a content type of "application/json" without any additional charset specification.

To resolve the issue, modify the code to remove "charset=utf8" from the Content-Type header:

<code class="java">con.setRequestProperty("Content-Type", "application/json");</code>
Copy after login

This change ensures that the request is sent with a content type of "application/json" only, which is what the server is expecting.

The above is the detailed content of Why Do I Get an HTTP 415 Unsupported Media Type Error When Sending a JSON Request?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!