As sugestões que encontrei aqui não foram suficientes para corrigir meu problema. Por isso estou abrindo o tópico.
Segue o código:
URL url = new URL("https://api.onvio.com.br/dominio/integration/v1/activation/enable");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
// Adicionando cabeçalhos
con.setRequestProperty("x-integration-key", xIntegrationKey);
con.setRequestProperty("Authorization", "Bearer " + authorization);
// Enviando requisição e lendo a resposta
int responseCode = con.getResponseCode();
con.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine= in.readLine()) != null) {
response.append(inputLine);
}
in.close();
Integration integrationKey = new Gson().fromJson(response.toString(), Integration.class);
return integrationKey.integrationKey;
E o erro que esta retornando:
java.io.IOException: Server returned HTTP response code: 411 for URL: https://api.onvio.com.br/dominio/integration/v1/activation/enable
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1964)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1959)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1958)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1528)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1512)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at testes.AutenticacaoAPI.GetKeyIntegrationApi(AutenticacaoAPI.java:95)
at testes.AutenticacaoAPI.main(AutenticacaoAPI.java:26)
Caused by: java.io.IOException: Server returned HTTP response code: 411 for URL: https://api.onvio.com.br/dominio/integration/v1/activation/enable
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1914)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1512)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:352)
at testes.AutenticacaoAPI.GetKeyIntegrationApi(AutenticacaoAPI.java:93)
... 1 more
Tentei definir o tamanho con.setRequestProperty("Content-Lenght", "0")
porém também não funciona.