Я исправил это, так как метод POST требовал тела, в то время как GET и DELETE не нужны тела, для аутентификации я использовал basicauth.
if (user_name != "" || password != "")
{
if (method == "POST")
{
// write body to query
String body = "username=" + user_name + "&password=" + password;
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(body);
writer.flush();
writer.close();
os.close();
}
else
{
String userpass = user_name + ":" + password;
String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));
connection.setRequestProperty ("Authorization", basicAuth);
InputStream in = connection.getInputStream();
}
}
// connect
connection.connect();
//results
String results = request_call_results(connection);
JSONObject json = String_toJson(results);
return json;