草庐IT

Okhttp实现参数请求接口用postman的form-data请求接口

1.看下图,是不是这种访问方式2.如果是这种访问方式,使用okhttp请求接口是这样的。//不良记录实体类BadnessCustomVoBeanbadnessCustomVoBean=newBadnessCustomVoBean();badnessCustomVoBean.setCategory("成品");Gsongson=newGson();//使用Gson将对象转换为json字符串Stringjson=gson.toJson(badnessCustomVoBean);MultipartBodyrequestBody=newMultipartBody.Builder().setType(M

java - RoboSpice 抛出 okhttp 异常

我使用RoboSpice-Retrofit调用我的服务器RESTapi,直到几天前它一直没有问题,现在每次调用都会抛出异常,示例:D/Retrofit:java.lang.NoSuchMethodError:Nodirectmethod(Lcom/squareup/okhttp/OkHttpClient;Lcom/squareup/okhttp/Request;ZZZLcom/squareup/okhttp/Connection;Lcom/squareup/okhttp/internal/http/RouteSelector;Lcom/squareup/okhttp/internal/

android - Okhttp 在与 Retrofit RxJavaCallAdapterFactory 一起使用时忽略 Dispatcher 设置

考虑以下OkHttp和Retrofit的初始化:publicstaticSomeServiceRestInterfacenewRestService(StringapiUrl){Retrofitretrofit=newRetrofit.Builder().baseUrl(apiUrl).client(createOkHttpClient()).addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io())).addConverterFactory(createGsonConverte

java - 如何解析从 OkHttp 返回的 XML?

这是我使用OkHttp的AsyncGet的OkHttpPost表单参数方法publicCallpostGetCountries(Callbackcallback){RequestBodybody=newFormEncodingBuilder().add("op","op").build();Log.d(TAG_PARAMS,"op=sgetcountrylist,app_type=1");Requestrequest=newRequest.Builder().url(GATEWAY_URL).post(body).build();Callcall=CLIENT.newCall(requ

java - 如何将数组添加到 okhttp 正文(POST)

现在我将数组作为字符串添加到正文中:RequestBodybody=newFormEncodingBuilder().add("profiles","[122,125,336]").build();但是服务器需要post参数数组。我怎样才能添加数组而不是字符串?okhttp可行吗? 最佳答案 您目前正在以字符串形式发布个人资料。您需要为profiles的复选框表单字段模拟POSTRequestBodybody=newFormEncodingBuilder().add("profiles[0]","122").add("profile

java - Android OkHttp InputStream java.IOException.closed

我使用OkHttpClient在服务器上下载数据库并将其复制到我的Android应用程序中,请求正常,我得到了好的内容。然而,当我尝试将我的byteStream写入我的文件时,我得到了一个java.IOException.closed。你知道我做错了什么吗?ResponsehttpResponse=webApiClient.execute(newWebApiRequest(WebApiMethod.DB_DOWNLOAD),context);if(httpResponse.code()==200){try{InputStreaminputStream=httpResponse.body

java - 如何使用 okhttp 执行 Reddit 帖子

我正在尝试使用RedditAPI来保存帖子。我知道我的请求格式有误,但我似乎找不到任何有关如何正确执行此操作的文档。如果有人能引导我朝着正确的方向前进,或者帮助我正确地格式化请求。这是我目前所拥有的。publicvoidsave(Viewv){OkHttpClientclient=newOkHttpClient();StringauthString=MainActivity.CLIENT_ID+":";StringencodedAuthString=Base64.encodeToString(authString.getBytes(),Base64.NO_WRAP);System.ou

android - 如何从响应改造中检索 cookie,okhttp?

我正在尝试从API响应中检索Cookie值,以在应用程序关闭时通过将cookie值设置为新的API调用来维护后端session:PostManRestClient对API调用的响应:RetrofitClient.javapublicstaticRetrofitgetClient(){if(checkClient()){returngetRetrofit();}HttpLoggingInterceptorinterceptor=newHttpLoggingInterceptor();interceptor.setLevel(HttpLoggingInterceptor.Level.BOD

java - Android 如何使用 OkHttp 从回调中获取响应字符串?

这是我的代码:OkHttpClientokHttpClient=newOkHttpClient();Requestrequest=newRequest.Builder().url("http://publicobject.com/helloworld.txt").build();Callbackcallback=newCallback(){@OverridepublicvoidonFailure(Requestrequest,IOExceptione){}@OverridepublicvoidonResponse(Responseresponse)throwsIOException{}

android - Glide 与 okhttp3 集成 java.lang.NoClassDefFoundError

我正在使用okhttp3和glide,所以我也添加了集成部分。compile'com.squareup.okhttp3:okhttp:3.2.0'compile'com.github.bumptech.glide:glide:3.6.1'compile'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'我什至使用启用了multidex支持compile'com.android.support:multidex:1.0.1'并将其添加到应用程序类@OverrideprotectedvoidattachBaseContext(Co