title: Is OkHttp equivalent code really OK in Postman?
body: <p>I'm trying to send a <code>json</code> post request to some API which in response sends a binary file back.</p>
  
  <p>I'm doing well in <code>Postman</code>:</p>
  
  <p>Header:</p>
  
  <p><a href="https://i.stack.imgur.com/oDeIl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oDeIl.jpg" alt="Headers"></a></p>
  
  <p>Body and result:</p>
  
  <p><a href="https://i.stack.imgur.com/V3CL6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V3CL6.jpg" alt="enter image description here"></a></p>
  
  <p>And I get the following code from <code>Code</code> section in <code>Postman</code> for <code>Java/OKHTTP</code></p>
  
  <pre><code>OkHttpClient client = new OkHttpClient();
  
  MediaType mediaType = MediaType.parse("application/json");
  RequestBody body = RequestBody.create(mediaType, "{\r\n  \"Text\":\"Hello\",\r\n  \"APIKey\":\"MY_API_KEY\",\r\n  \"Speaker\":\"Female1\",\r\n  \"Format\":\"mp3/32/m\",\r\n  \"Quality\":\"quality/normal\"\r\n}");
  Request request = new Request.Builder()
    .url("http://url/CloudService/ReadText")
    .post(body)
    .addHeader("content-type", "application/json")
    .addHeader("cache-control", "no-cache")
    .addHeader("postman-token", "0a1ce7c9-7a95-a2b9-7cde-8a7e6ce58386")
    .build();
  
  Response response = client.newCall(request).execute();
  </code></pre>
  
  <p>But when I use the above code in android it fails, I'm sure that I got Internet permission and the code is executed within an <code>AsyncTask</code>.</p>
  
  <p>I'm not asking about the API or how to send <code>json</code> <code>Post</code> request to some API and get a binary file in response. I've used <code>client.newCall(request).enqueue(new Callback(){//stuff here});</code> but none works. In response I got a 307 status code (instead of 200 in <code>Postman</code>) and no binary data at all. The API is very unclear and said nothing about the failure and I'm still working on that.  </p>
  
  <p><strong>All I'm asking</strong> is that does <code>Postman</code> generates equivalent code for <code>OkHttp</code> correctly? and if not what is your suggestion for equivalent of this request in <code>Java/OkHttp</code>?</p>
  
  <p>Just to provide another example, the following is also a working <code>Python</code> <code>requests</code> script to do the same job:</p>
  
  <pre><code>url = 'http://url/CloudService/ReadText'
  api_key = 'MY_API_KEY'
  body = {
      'Text': 'Hello',
      'Speaker': 'Female1',
      'Format': 'mp3/32/m',
      'Quality': 'quality/normal',
      'APIKey': api_key
  }
  header = {
      'Content-type': 'application/json'
  }
  
  r = requests.post(url, data=json.dumps(body), headers=header)
  </code></pre>