title: Java HttpServlet unable to receive any parameters from POST request made by client using OKHttp
body: <p>This is the log from the server:</p>
  
  <pre><code>POST Request reader reads:--3cd58f21-8ffa-46a0-b1c0-0e4660c2ca28
  POST Request reader reads:Content-Disposition: form-data; name="device"
  POST Request reader reads:Content-Length: 163
  POST Request reader reads:
  POST Request reader reads:{"deviceId":"5ccf7f0fb7b1","manufacturer":"Wow Lamp","name":"Wow-b7b1","type":"lamp","userId":"amzn1.account.AGGL3JOPQ3UTF74KQY2TJCYSYNAQ","timer":0,"chosen":true}
  POST Request reader reads:--3cd58f21-8ffa-46a0-b1c0-0e4660c2ca28--
  </code></pre>
  
  <p>The result above is what the reader read from the request. But if getParameter is called from the request instance, the parameter map is null.</p>
  
  <p>This is the content of the parameter map:</p>
  
  <pre><code>POST Request:{}
  </code></pre>
  
  <p>As you can see, the map contains no parameter, but the reader can read the data sent by the client.</p>
  
  <p>This is the code of the server:</p>
  
  <pre><code>@Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException
  {       
      System.out.println("POST Request:" + req.getParameterMap());
  
      if(isPostRequestValid(req))
      {
          try 
          {
              handleRequest(req);
          } 
  
          catch (JSONException e) 
          {
              e.printStackTrace();
          }
      }
  
      sendResponse(resp);
  
      try 
      {
          BufferedReader reader = req.getReader();
  
          String inputLine;
  
          while((inputLine = reader.readLine()) != null) 
          {
              System.out.println("POST Request reader reads:" + inputLine);
          }
      } 
  
      catch (IOException e) 
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>There must be some coding mistake in the client side</p>
  
  <p>This is the code of the client:</p>
  
  <pre><code>new Thread(new Runnable() {
              @Override
              public void run() {
                  OkHttpClient client = new OkHttpClient();
  
                  RequestBody requestBody = new MultipartBuilder()
                          .type(MultipartBuilder.FORM) //this is what I say in my POSTman (Chrome plugin)
                          .addFormDataPart("device", device)
                          .build();
  
                  Request request = new Request.Builder()
                          .url(Constant.BASE_URL + "update_device.html")
                          .post(requestBody)
                          .build();
                  try {
                      Response response = client.newCall(request).execute();
                      String responseString = response.body().string();
                      response.body().close();
                      // do whatever you need to do with responseString
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }).start();
  </code></pre>
  
  <p>But the client side did use form data, so what can be wrong here?</p>