tamicer / retrofitclient Goto Github PK
View Code? Open in Web Editor NEW基于Retrofit2.x和Rxjava2.x封装的请求工具类(内含Retrofit2.x & rxjava1.x)
License: Apache License 2.0
基于Retrofit2.x和Rxjava2.x封装的请求工具类(内含Retrofit2.x & rxjava1.x)
License: Apache License 2.0
还得是你啊 RetrofitClient类一行注释没有
PersistentCookieStore.java的66行是否应该改为if (cookie.persistent())
运行报错RuntimeExcepiton
动态url传入拼接报错。
日志显示 :
动态URL最终拼接后
<-- 200 OK http://ip.taobao.com/service%2FgetIpInfo.php?ip=21.22.11.33 (13ms)
普通的
http://ip.taobao.com/service/getIpInfo.php?ip=21.22.11.33 (11ms)
。
DownLoadManager里面的"下载进度"不是写文件的进度吗,writeResponseBodyToDisk方法的ResponseBody是下载完成后才有的
下面的链接采用的Retrofit 2.0 +RaJava 1.0 的文章,我想了解取消的做法
demo不可用
执行executePost()和json()方法的时候报错,错误如下面
java.lang.ClassCastException: okhttp3.ResponseBody$1 cannot be cast to com.tamic.retrofitclient.net.BaseResponse
执行executeGet的时候也报错,应该是gson在转换的时候包错的,应该是在runtime的时候无法获取正确的type,请问要怎样解决
你的demo下载下来,报错:Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.,请问怎么解决?
java.lang.ClassCastException: okhttp3.ResponseBody$1 cannot be cast to com.tamic.retrofitclient.net.BaseResponse
一直提示这个 无法转换
请求404了,作者可以重新修改看看不?
是否可以处理下内存泄漏?
大神 我现在下载大文件,点击下载一直没有反应,小文件是没有问题的,怎么解决
没有Rxjava2的
你好,
我APP内用的是这个方法上传图片+参数
@post()
Flowable upload(@url String url, @Body RequestBody Body);
调用方式如下:
public Flowable upload(String url, Map<String, String> params, Map<String, String> files) {
final MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
Flowable.fromIterable(params.entrySet()).subscribe(
new Consumer<Map.Entry<String, String>>() {
@OverRide
public void accept(Map.Entry<String, String> entry) throws Exception {
builder.addFormDataPart(entry.getKey(), entry.getValue());
}
});
if (files != null && files.size() > 0) {
//多张图片
Flowable.fromIterable(files.entrySet()).subscribe(
new Consumer<Map.Entry<String, String>>() {
@OverRide
public void accept(Map.Entry<String, String> entry) throws Exception {
File file = new File(entry.getValue());//filePath 图片地址
RequestBody imageBody = RequestBody.create(MediaType.parse("image/*"), file);
builder.addFormDataPart(entry.getKey(), file.getName(),imageBody);
}
});
}
LogUtils.d(API_TAG, "upload url = " + url +
" :: params = " + params.toString() +
" :: files = " + files.toString());
return bindLifeCycle(getIBaseService().upload(url, builder.build()));
}
结果发现服务器那边都收不到我发送过去的图片,不知道什么原因,请问你们一般是如何上传图片+参数的呢?
478104175 加下QQ 为什么这么多年还没更新
08-22 19:06:40.743 6767-6767/com.tamic.retrofitclient E/Tamic: java.io.IOException: unexpected end of stream on okhttp3.Address@ecf82dd4
08-22 19:06:40.743 6767-6767/com.tamic.retrofitclient E/Lyk: java.io.IOException: unexpected end of stream on okhttp3.Address@ecf82dd4
08-22 19:06:58.273 6767-6767/com.tamic.retrofitclient E/Tamic: java.net.SocketTimeoutException
08-22 19:06:58.273 6767-6767/com.tamic.retrofitclient E/Lyk: java.net.SocketTimeoutException
08-22 19:07:06.173 6767-6767/com.tamic.retrofitclient E/Tamic: com.google.gson.internal.LinkedTreeMap cannot be cast to com.tamic.retrofitclient.IpResult
08-22 19:07:06.173 6767-6767/com.tamic.retrofitclient E/Lyk: java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.tamic.retrofitclient.IpResult
08-22 19:09:22.093 11669-11669/com.tamic.retrofitclient E/Tamic: java.lang.ClassCastException: okhttp3.ResponseBody$1 cannot be cast to com.tamic.retrofitclient.net.BaseResponse
08-22 19:09:22.093 11669-11669/com.tamic.retrofitclient E/Lyk: java.lang.ClassCastException: okhttp3.ResponseBody$1 cannot be cast to com.tamic.retrofitclient.net.BaseResponse
点第一请求个出现:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 19 path $.data
点第二个请求出现:java.lang.RuntimeException
根据log,可以得到网络请求成功了并拿到了数据。但onNext回调没有执行
看到你的文章 http://www.jianshu.com/p/1a5f14b63f47 我才用了interceptror的方法来持久化cookie。
代码如下
public class SaveCookiesInterceptor implements Interceptor {
private static final String TAG = "SaveCookiesInterceptor";
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
if (!originalResponse.headers("Set-Cookie").isEmpty()) {
HashSet<String> cookies = new HashSet<>();
cookies.addAll(originalResponse.headers("Set-Cookie"));
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(App.context);
if (sharedPreferences.getStringSet("cookies", null) == null) {
Log.d(TAG, "intercept: " + cookies.toString());
sharedPreferences.edit()
.putStringSet("cookies", cookies)
.apply();
}
}
return originalResponse;
}
}
如你所见我加了一行 if (sharedPreferences.getStringSet("cookies", null) == null) {
的判断。
这是因为遇到一个问题:模拟登陆成功,但是获取个人资料页返回的是登录页面的数据。然后我经过尝试加了那行代码就好了。请问这是为什么?有可能是什么原因?谢谢
demo 下载下来编译器通不过Gradle project sync failed .Basic functionality(e.g.editing,debugging)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.