I'm trying to make a request for a webservice that uses OAuth to generate an access token. But even though the request returns the Http 200 code, json appears only as {"errors": {"internal": ["500"]}} , below the code:
NOTE: I did the same procedure for the terminal using curl and the data was generated normally.
URL url = new URL( "https://api.myapi.com.br/api/oauth/token" );
HttpURLConnection huc = ( HttpURLConnection ) url.openConnection();
huc.setRequestMethod( "POST" );
huc.setRequestProperty( "grant_type", "client_credentials" );
huc.setRequestProperty( "client_id", CLIENT_ID );
huc.setRequestProperty( "client_secret", CLIENT_SECRET );
if ( huc.getResponseCode() == HttpURLConnection.HTTP_OK )
{
BufferedReader br = new BufferedReader( new InputStreamReader( huc.getInputStream(), "UTF-8" ) );
while ( ( line = br.readLine() ) != null )
{
content.append( line );
}
JSONObject json = new JSONObject( content.toString() );
System.out.println( json );
}