0

I have been using HttpClient to connect android with Django. Now i need to find out the response code . I tired the following

String url = "http://10.0.2.2:8000/api/ecp/profile/?format=json";
HttpClient client = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
httpget.setHeader("AUTHORIZATION", un.getText().toString()+":"+hash);
client.execute(httpget);
int code = client.getStatusLine().getStatusCode();  

but it throws following error

The method getStatusLine() is undefined for the type HttpClient

Any idea what to do? Thanx

4

2 回答 2

2

you should do it on response not client

HttpResponse respone=client.execute(httpget);

 int athul=respone.getStatusLine().getStatusCode
于 2012-09-03T11:31:07.787 回答
0

You can try this code.May be it will be helpful for you.

final HttpResponse res = httpClient.execute(httpget);

    final String code = res.getStatusLine().toString();
于 2012-09-03T11:37:25.040 回答