August 03, 2018

How to use xml x-www-form-urlencoded and logging in okhttp

How to use xml x-www-form-urlencoded and logging in okhttp

/**
* Consumerfed IT Section Kozhikode
*/

private String okhttpPost(String xmlRequest) {

String responseStr = null;
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BASIC);
OkHttpClient client = new OkHttpClient().newBuilder().addInterceptor(logging).connectTimeout(60, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).build();
RequestBody formBody = new FormBody.Builder().add("XML", xmlRequest).build();
Request request = new Request.Builder().url("https://consumerfed/itsection/findData").post(formBody).addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("Connection", "Keep-Alive").addHeader("Accept-Language", "en-US").addHeader("Accept-Encoding", "application/gzip").build();
try {Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
responseStr = response.body().string();}} catch (IOException exception) {
exception.printStackTrace();}
return responseStr;
}

InterruptedIOException



java.io.InterruptedIOException: thread interrupted
at okio.Timeout.throwIfReached(Timeout.java:145)
at okio.Okio$1.write(Okio.java:75


okhttp will check whether current running is interrupted. so check the main thread, why the main thread is interrupted , may be you have to increase the waiting time of that thread

Facebook comments