import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.DataOutputStream;
I was correctly passing
Content-Type: application/json
But my server was still rejecting the request because I was also passing
Accept: application/json
Which was not allowed in my case.
The HTTP response code you get is
415 Unsupported Media Type
This means that the server can not handle the format you sent to it. Your HTTP request sets this header:
Content-Type: application/x-www-form-urlencoded
This is the content type sent by a browser if a form is submitted. If you want to send JSON, use this header:
Content-Type: application/json