Enviar solicitação HTTP GET com cabeçalho
No meu aplicativo Android, desejo solicitar um URL com parâmetros GET e ler a resposta. Na solicitação, devo adicionar umx-zip
cabeçalho.
A URL é algo como
http://example.com/getmethod.aspx?id=111&method=Test
lguém pode me fornecer um código para iss
Duas coisas são importantes: é uma solicitação GET e contém ox-zip
cabeçalho.
EDITAR
try {
HttpClient client = new DefaultHttpClient();
String getURL = "http://example.com/getmethod.aspx?id=111&method=Test";
HttpGet get = new HttpGet(getURL);
get.setHeader("Content-Type", "application/x-zip");
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
//do something with the response
Log.i("GET ",EntityUtils.toString(resEntityGet));
}
} catch (Exception e) {
e.printStackTrace();
}
Tento com este código, mas recebo código com o erro .net:Object reference not set to an instance of an object...
Eu acho, mas não tenho certeza se isso forx-zip
header, o cabeçalho está no meu código ok?