android设置http参数HttpConnectionParams和HttpClient,HttpGet
来源:互联网 发布:erp系统数据库设计 编辑:程序博客网 时间:2024/05/17 06:24
try {
// 创建 HttpParams 以用来设置 HTTP 参数(这一部分不是必需的)
HttpParams params = new BasicHttpParams();
// 设置连接超时和 Socket 超时,以及 Socket 缓存大小
HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
HttpConnectionParams.setSoTimeout(params, 20 * 1000);
HttpConnectionParams.setSocketBufferSize(params, 8192);
// 设置重定向,缺省为 true
HttpClientParams.setRedirecting(params, true);
// 设置 user agent
HttpProtocolParams.setUserAgent(params, userAgent);
// 创建一个 HttpClient 实例
// 注意 HttpClient httpClient = new HttpClient(); 是Commons HttpClient
// 中的用法,在 Android 1.5 中我们需要使用 Apache 的缺省实现 DefaultHttpClient
HttpClient httpClient = new DefaultHttpClient(params);
// 创建 HttpGet 方法,该方法会自动处理 URL 地址的重定向
HttpGet httpGet = new HttpGet (“http://www.test_test.com/”);
HttpResponse response = client.execute(httpGet);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
// 错误处理,例如可以在该请求正常结束前将其中断
httpGet.abort();
}
// 读取更多信息
Header[] headers = response.getHeaders();
HttpEntity entity = response.getEntity();
Header header = response.getFirstHeader(“Content-Type”);
InputStream content = entity.getContent();
BufferedInputStream bis = new BufferedInputStream(content);
StringBuilder builder = new StringBuilder();
int b;
while((b=bis.read()) != -1){
builder.append((char)b);
}
String resultStr = builder.toString();
Log.v("result", resultStr);
BufferedInputStream bis = new BufferedInputStream(content);
StringBuilder builder = new StringBuilder();
int b;
while((b=bis.read()) != -1){
builder.append((char)b);
}
String resultStr = builder.toString();
Log.v("result", resultStr);
} catch (Exception ee) {
} finally {
// 释放连接
client.getConnectionManager().shutdown();
}
- android设置http参数HttpConnectionParams和HttpClient,HttpGet
- HttpClient和HttpGet 设置参数的优先级
- Android - HTTPClient模块的HttpGet和HttpPost
- angular使用Http和HttpClient设置查询参数的区别
- Android HttpGet和HttpPost设置超时
- Android HttpGet和HttpPost设置超时
- Android HttpGet和HttpPost设置超时
- Android HttpGet和HttpPost设置超时
- Android中HttpGet和HttpPost设置超时
- Android HttpGet和HttpPost设置超时
- HttpClient常用HttpGet和HttpPost
- android httpget httppost 请求,超时参数的设置
- HTTPClient模块的HttpGet和HttpPost(处理http请求响应)
- HttpClient,HttpGet
- android开发httpGet httpPost httpURLConnection httpClient
- Android网络编程之HttpClient&HttpGet&HttpPost
- android api23找不到HttpClient,HttpGet等解决方法
- HTTPClient模块的HttpGet和HttpPost
- instance method '-methodName' not found (return type defaults to 'id')
- 密码即将过期提示的影响简析(SP2-0619、SP2-0611)
- 包装类DataOutputStream、DataInputStream的常见用法
- 解决Linux NFS umount 'device is busy' and 'df -h' hang
- Starling Flash游戏框架游戏开发的介绍与安装
- android设置http参数HttpConnectionParams和HttpClient,HttpGet
- tcp sack选项
- WEB组件化
- nginx tomcat负载均衡之文件上传访问策略
- struts2核心工作流程与原理
- STUN和TURN技术浅析
- 建站基础一
- 项目管理六大阶段 --美国IT项目管理硕士笔记(三)
- PLSQL导入导出数据库