android使用okthtp
来源:互联网 发布:android 开启网络权限 编辑:程序博客网 时间:2024/04/29 10:29
androidstudio配置:
异常:Failed resolutionof:Lokhttp3/OkHttpClient;
解决方法:添加依赖项:
compile files('libs/okhttp-3.3.1.jar')
compile 'com.squareup.okhttp:okhttp:2.0.0'
异常:Failed resolutionof:Lokio/ForwardingTimeout;
解决方法:添加依赖项:
compile files('libs/okio-1.6.0.jar')
异常:Duplicatefiles copied in APKMETA-INF/maven/com.squareup.okio/okio/pom.properties
还需要build.gradle添加:
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude'META-INF/LICENSE.txt'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}
官网:
https://github.com/square/okhttp
github例子:
https://github.com/hongyangAndroid/okhttp-utils
简单封装:
https://github.com/neil2hw/OkHttpManager/blob/master/OkHttpManager.java
使用例子:
OkHttpClient client = new OkHttpClient();
URL url = null;
try {
url = new URL("http://blog.csdn.net/gaolu");
Request request = new Request.Builder().url(url).build();
Response response =client.newCall(request).execute();
String aaa = response.body().string();
Log.e("aaa",aaa);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
使用例子:
String url ="http://www.csdn.net/";
OkHttpUtils
.get()
.url(url)
.addParams("username", "hyman")
.addParams("password", "123")
.build()
.execute(newStringCallback()
{
@Overridepublicvoid onError(Request request, Exception e)
{
}
@Overridepublicvoid onResponse(String response)
{
}
});
- android使用okthtp
- Android使用
- Android使用
- Android使用
- 【android】 android studio使用
- android使用keytools使用
- 【Android】Android LogCat使用详解
- 【Android】Android LogCat使用详解
- Android:Android Fragments 详细使用
- android布局 android:Theme使用
- #android#android studio 使用cardview
- 【android】:android之使用Intent
- 【Android】Android对话框的使用
- 【Android】android Fragment的使用
- 【Android】Android SurfaceView使用详解
- Android进阶---android databinding 使用
- android:Android中pullToRefresh使用
- Android WebView使用【初级使用】
- 解决跨域的代码
- 关于电脑未联网状态下,navicat for mysql 连接数据库不成功的解决办法
- 数据结构——线性表顺序表示和实现
- HDU1496:Equations(二分)
- Google下拉刷新控件SwipeRefreshLayout
- android使用okthtp
- saltstack实践案例
- ElasticSearch环境搭建
- PAT 1082
- 1019. General Palindromic Number (20)
- java自动生成数据库代码
- Android Studio 插件配置加载卡住/插件所在文件目录管理
- Java 继承接口同名函数问题
- 有关TextView的进阶应用(一)