okhttp3

OkHTTPClient Proxy authentication how to?

Deadly 提交于 2019-11-26 15:58:49
问题 Question: How do I add a authorization proxy to OkHTTP. I know that OkHTTP's builder does support proxies although I am having a hard time setting one up. /** * Given a Url and a base64 encoded password return the contents of a website. * @param urlString * @param password * @return JSON */ public String getURLJson(String urlString, String password) { OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(60, TimeUnit.SECONDS) .writeTimeout(60, TimeUnit.SECONDS) .readTimeout(60,

Image upload using okHttp

徘徊边缘 提交于 2019-11-26 08:27:32
问题 i want to upload image using okhttp but i am not able to find MultipartBuilder for Post Image.What can i use instead of this. Here is my code public static JSONObject uploadImage(File file) { try { final MediaType MEDIA_TYPE_PNG = MediaType.parse(\"image/png\"); RequestBody req = new MultipartBuilder().setType(MultipartBody.FORM).addFormDataPart(\"userid\", \"8457851245\") .addFormDataPart(\"userfile\",\"profile.png\", RequestBody.create(MEDIA_TYPE_PNG, file)).build(); Request request = new

Logging with Retrofit 2

女生的网名这么多〃 提交于 2019-11-26 01:26:26
问题 I\'m trying to get the exact JSON that is being sent in the request. Here is my code: OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor(){ @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException { Request request = chain.request(); Log.e(String.format(\"\\nrequest:\\n%s\\nheaders:\\n%s\", request.body().toString(), request.headers())); com.squareup.okhttp.Response response = chain.proceed(request); return response; } });