Using OkHttp3 to send a MultipartBody
<p>I'm writing an android app that needs to communicate with a server. I'm struggling to make a MultipartBody for OkHttp3 to use. My code looks like this:</p>

<pre><code>OkHttpClient client = new OkHttpClient();

try 
{
    RequestBody requestBody = new MultipartBody.Builder()
                    .setType(MultipartBody.FORM)
                    .addFormDataPart("someKey1", "someString1")
                    .addFormDataPart("someKey2", "someString2")
                    .build();
    System.out.println(requestBody.toString());

    Request request = new Request.Builder()
                    .url("server url")
                    .post(requestBody)
                    .build();

    Response response = client.newCall(request).execute();
    return response;
}
catch (IOException e)
{
    e.printStackTrace();
    return false;
}
</code></pre>

<p>This is pretty much the standard code everyone uses. The server receives the request, but I can't get the MultipartBody from the request. When the multipart body is printed, it looks like this:</p>

<pre><code>I/System.out: okhttp3.MultipartBody@14040826
</code></pre>

<p>So my questions are: Why doesn't it contain my data and should it? Am I missing a library (I included compile 'com.squareup.okhttp3:okhttp:3.2.0' in the gradle and assume MultipartBody is part of this library)? What is a MultipartBody supposed to look like?</p>

<p>I tried sending a FormBody as well but it looks the same.</p>