HttpClient androidStudio基本的使用方法
来源:互联网 发布:网络视频营销 编辑:程序博客网 时间:2024/05/17 06:06
modle的buil.gradle文件中android根标签下 添加useLibrary 'org.apache.http.legacy'
/**
* httpClient-- apche 基金会维护的请求网络的工具;
工具类
*/
public class NetWorkUtils {
public String tag = "NetWorkUtils";
/**
* apache
*
* @param jsonUrl
* @return
*/
public String getJsonByHttpClientGet(String jsonUrl) {
//获取httpclient对象
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
//准备一个get请求
// HttpGet httpGet = new HttpGet(jsonUrl);
HttpPost httpPost = new HttpPost(jsonUrl);
try {
//得到服务器返回的数据;
HttpResponse response = defaultHttpClient.execute(httpPost);
//得到状态码
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode ==200){
//entiry 里面封装的数据;
HttpEntity entity = response.getEntity();
//这个result就是json字符串,剩下的就是解析工作了;
String result = EntityUtils.toString(entity);
Log.e(TAG, "result: "+result );
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
- HttpClient androidStudio基本的使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- Android HttpClient基本使用方法
- HttpClient类包基本使用方法
- Android HttpClient,httpPost基本使用方法
- HttpClient类包基本使用方法
- HttpComponents之httpclient基本使用方法
- androidStudio没有httpclient的解决办法
- Android HttpClient基本使用方法!!--get和post
- AndroidStudio的基本设置
- AndroidStudio的基本配置
- AndroidStudio中找不到HttpClient的解决办法
- Java线程相关知识
- maven 打包 时出现非法字符: /65279错误
- apache 配置 404页面
- Android 网络框架 Retrofit2.0介绍、使用和封装
- TreeMap
- HttpClient androidStudio基本的使用方法
- ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file:
- Creating a ROS msg and srv
- Excel公式与函数笔记—第一篇
- HttpClient androidStudio中的基础使用
- Ehcache配置问题(二)Element <cache> does not allow attribute "maxEntriesLocalHeap".
- AE开发中,对 COM 组件的调用返回了错误 HRESULT E_FAIL,在地理处理中,即GP工具处理时出错
- Jstorm 动态更新配置文件出错
- ddtek.oracle.dll使用相关