I am trying to use OkHttpClient to post json data from Android to my server.
My code:
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
private String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
Build error occurs here: RequestBody body = RequestBody.create(JSON, json);
Error: Error:(65, 39) error: cannot access ByteString class file for okio.ByteString not found
I have copied the downloaded jar file from OkHttp (it's 3.0.1) to libs folder. Am I missing anything? What is causing the error?