title: How to map curl into java okhttp?
body: <p>I have got a basic curl like below:</p>
  
  <pre><code>curl -X POST \
      'https://aogt.pl/auth/' \
      -H 'Authorization: Basic NGZjMjExNWQyYTZk' \
      -H 'Content-Type: application/x-www-form-urlencoded' \
      -d 'client_id=4fc2115'
  </code></pre>
  
  <p>When I run it in the console on e.g. Ubuntu everything work correctly, I get a good response. Now I would like to map this curl into the java code using okhttp. I write below code:</p>
  
  <pre><code>public class TestMain {
      private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
      public static void main(String[] args) throws IOException {
          String data = "client_id=4fc2115";
          RequestBody body = RequestBody.create(JSON, data);
          Request request = new Request.Builder()
                  .url("https://aogt.pl/auth/")
                  .addHeader("Authorization", "Basic NGZjMjExNWQyYTZk")
                  .addHeader("Content-Type", "application/x-www-form-urlencoded")
                  .post(body)
                  .build();
          OkHttpClient client = new OkHttpClient();
          Response response = client.newCall(request).execute();
          System.out.println(response.body().string());
      }
  }
  </code></pre>
  
  <p>The pom file look like:</p>
  
  <pre><code>&lt;dependencies&gt;
     &lt;dependency&gt;
        &lt;groupId&gt;com.squareup.okhttp3&lt;/groupId&gt;
           &lt;artifactId&gt;okhttp&lt;/artifactId&gt;
        &lt;version&gt;4.2.0&lt;/version&gt;
     &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>The problem is that when I run this code I get "400 Bad Request" so this is problem with server. I wrong map above curl into the java code into the http. Probably the problem is in POST body, because it is not JSON, but what I need to change here, could you please tell me what is wrong? Thank you very much.</p>