HttpClient androidStudio中的基础使用
来源:互联网 发布:网络视频营销 编辑:程序博客网 时间:2024/06/07 02:11
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中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- HttpClient androidStudio中的基础使用
- 03HttpClient androidStudio中的基础使用
- HttpClient网络请求 androidStudio中的基础使用
- androidStudio中的HttpClient
- HttpClient在 AndroidStudio中使用
- androidstudio中无法使用HttpClient问题
- AndroidStudio中HttpClient的简单使用
- HttpClient使用基础
- 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使用相关
- 算法爱好者——寻找重复的数 ? 待解决
- Linux shuf --随机选择器
- [App] Firewalld 基础用法
- zcmu-1181(大数相加)