retrofit使用注意事项
2016-01-19 11:31
393 查看
1.上传文件
遇到错误:java.lang.IllegalStateException: JSON must start with an array or an object.
Multipart requests are used when
present on the method. Parts are declared using the
更多讨论结果https://github.com/square/retrofit/issues/1063
2.设置超时时间(okhttp3)
http://www.veritas.com/community/forums/client-read-and-client-connect-time-out Nicolai和 mph999的回答
简单点就是connectTimeout就是和服务器建立连接的时间;readTimeout是响应请求
3.获得服务器返回的json字符串
注意Bean的类型
然后在请求的回调方法onResponse中获取json字符串
String jsonString = new String(response.body().bytes());
遇到错误:java.lang.IllegalStateException: JSON must start with an array or an object.
Multipart requests are used when
@Multipartis
present on the method. Parts are declared using the
@Partannotation.
@Multipart @PUT("user/photo") Call<User> updateUser(@Part("photo") RequestBody photo, @Part("description") RequestBody description);注意:类型必须是 RequestBody
更多讨论结果https://github.com/square/retrofit/issues/1063
2.设置超时时间(okhttp3)
OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build();区别:
http://www.veritas.com/community/forums/client-read-and-client-connect-time-out Nicolai和 mph999的回答
简单点就是connectTimeout就是和服务器建立连接的时间;readTimeout是响应请求
3.获得服务器返回的json字符串
注意Bean的类型
@GET("url") Call<ResponseBody> getHome();
然后在请求的回调方法onResponse中获取json字符串
String jsonString = new String(response.body().bytes());
相关文章推荐
- 《python》学习笔记(Day2),读入磁盘文件,经过处理,保存成相应的磁盘文件
- CUDA编程——Mars:MapReduce on GPU
- MCMC and faster Gibbs Sampling using Rcpp
- -----下面是二叉树的定义-----储存---
- android 图片处理工具
- sql语法大全
- Unity学习日记-使用脚本进行音频资源的读取,Resources.LoadAll
- Java开发必会的Linux命令
- Linux常用命令大全
- Xcode 7智能测试化工具XCTestCase学习
- 多线程初探(五)
- CentOS6.5下Mysql 未设置query_cache_size 导致CPU占用率高的问题解决方法_20160119_莫小贝
- redis集群操作
- IOS开发之UIScrollViewDelegate详解
- Subsets
- 数据类型与运算符简介
- Navicat for MySQL 11.X激活
- ORACLE 对用户密码做限制
- C++中变量,函数的作用域和生命周期?
- Android 讲解:数据共享