HttpClient在Android Studio中使用
来源:互联网 发布:csgo mac版 编辑:程序博客网 时间:2024/05/21 17:23
build.gradle中写入
android {useLibrary 'org.apache.http.legacy'
}
代码
//因为请求的是https协议的网址,eclipse下使用HttpGet请求会报错,需要添加以下这行代码
SSLSocketFactory.getSocketFactory().setHostnameVerifier(new AllowAllHostnameVerifier());//1.创建HttpClientHttpClient hc=new DefaultHttpClient();//2.创建HttpGet对象HttpGet hg = new HttpGet(strings[0]);//3.执行请求try { HttpResponse response = hc.execute(hg); //4.得到结果吗 int code = response.getStatusLine().getStatusCode(); if(code==200){ //5.得到结果数据 HttpEntity result = response.getEntity(); String string = EntityUtils.toString(result); Log.e("TTTTTT",string+"++++++++++++++tttt"); return string; }} catch (IOException e) { e.printStackTrace();}
阅读全文
1 0
- 如何在Android Studio中使用HttpClient
- HttpClient在Android Studio中使用
- HttpClient在Android Studio中无法使用的问题。
- HttpClient在 Android Studio中的使用
- Android studio 中使用Httpclient权限
- android studio 使用httpclient
- android studio中在api23版本中使用HttpClient的问题
- HttpClient在Android Studio中报错
- 在Android 6.0 中使用HttpClient
- android studio 在API23下,怎么使用HttpClient
- 在Visual Studio 2012中编译使用HttpClient时
- android studio中HttpClient解决
- Android studio使用HttpClient出错
- android studio不能使用HttpClient
- Android中使用HttpClient
- httpclient在android studio中用不了
- 【Android】在android studio中使用assert
- 在android中使用HTTPClient以post方法发送二进制文件
- Icpc训练赛 + 国庆大礼包
- java实现希尔排序
- Codeforces Round#412 C Success Rate
- Rxjava2-小白入门(二)
- 【JavaScript】DOM基础
- HttpClient在Android Studio中使用
- 完美队形(区间dp)
- UVa10870
- Codeforces Beta Round #86 (Div. 2 Only) E Double Happiness 素数筛法,费马平方和定理
- 数据结构之图
- //使用**异步**任务方式 HttpUrlConnection方式 要在清单列表设置连接网络权限
- ContentNegotiatingViewResolver解析器
- Android第一行代码-编写聊天界面-问题解决方案
- bzoj1969: [Ahoi2005]LANE 航线规划