您的位置:首页 > 理论基础 > 计算机网络

使用Android内置httpRequest发起httpRequest

2011-11-11 03:59 211 查看
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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: