使用Android内置httpRequest发起httpRequest

package com.leo.rowe;


import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;


public class HttpHelp {
private String url;
HttpClient httpClient ;
HttpGet httpget;
HttpResponse httpResponse;
String response = null;


HttpHelp(String url) {
this.url = url;
System.out.println("class have beee set");
httpClient= new DefaultHttpClient();
httpget=  new HttpGet(url);
}


String getHttp( ) {


try {
System.out.println("set http!");
httpResponse = httpClient.execute(httpget);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
System.out.println("get information 200");
response = EntityUtils.toString(httpResponse.getEntity());
} else {
response = "statusNum: " + statusCode;
}
} catch (Exception e) {
System.out.println(e);
}
return response;
}


}

你可能感兴趣的:(使用Android内置httpRequest发起httpRequest)