1
votes

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?

1
After copying the jar file inside libs folder did you tell Android Studio to include it as library? - Skyyy

1 Answers

2
votes

I was having same issue okio.ByteString not found. I found a github issue.

its a separate package we need to include by our self.

You can find the latest jar here