使用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;
}
}
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] WebView内的本地网页,使用XMLHttpRequest读取本地档案
- android下使用HttpClient发起get和post请求
- JSP内置对象的使用 request,response,session(一)
- Android中Retrofit+OkHttp进行HTTP网络编程的使用指南
- Android使用HTTP协议访问网络——HttpClient
- JSP内置对象:Request和Response的简单介绍及使用
- android 网络编程 HttpGet类和HttpPost类使用详解
- xmlHttpRequest对象的使用
- Android访问网络,使用HttpURLConnection还是HttpClient?
- ASIHttpRequest 类库的使用说明
- ASIHTTPRequest的使用——介绍说明
- 使用android真机测试http网络连接异常解决办法
- SpringMVC上传图片总结(1)-Web Uploader--常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- 使用HttpWebRequest抓取网页
- Android使用AsyncTask加http用post方式上传图片到服务器
- Android网络请求库——android-async-http使用
- 开源框架android-async-http使用
- iOS开发asi使用(二)ASIHttpRequest发送数据
- 使用httpwebrequest发送数据到网站
- Delphi中使用IXMLHTTPRequest如何用POST方式提交带参