Ao criar a activity de conexão no campo connection.getRequestMethod("POST"); não aceita o método Post.
sou novato na área, poderiam me ajudar?
public static String postdados(String urlusuario, String parametrousuario) {
URL url;
HttpURLConnection connection = null;
try{
url = new URL (urlusuario);
connection = (HttpURLConnection) url.openConnection();
connection.getRequestMethod("POST");
connection.setRequestProperty( "content-type", "application/x-www-form-urlencoded" );
connection.setRequestProperty( "content-lenght", "" + Integer.toString( parametrousuario.getBytes().length ) );
connection.setRequestProperty( "content-language", "pt-BR");
connection.setUseCaches( false );
connection.setDoInput( true );
connection.setDoOutput( true );
DataOutputStream dataOutputStream = new DataOutputStream( connection.getOutputStream());
dataOutputStream.writeBytes(parametrousuario);
dataOutputStream.flush();
InputStream inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) );
String linha;
StringBuffer resposta = new StringBuffer();
while ((linha = bufferedReader.readLine()) != null) {
resposta.append( linha );
resposta.append( '\r' );
}
bufferedReader.close();
return resposta.toString();
} catch (Exception erro){
return null;
}finally {
if (connection !=null){
connection.disconnect();
}
}
}
}