title: How do I pass json as a query parameter on Rest Post web service in java
body: <p>How do I pass json as a query parameter on Rest Post web service in java</p>
  
  <p>For example:</p>
  
  <p><a href="https://testvpa.net/WebService/ViALoggingRestWS/ViALoggingService.svc/StartCall" rel="nofollow noreferrer">https://testvpa.net/WebService/ViALoggingRestWS/ViALoggingService.svc/StartCall</a>?<code>parameter={"machineName":"KK-IVR01","appName":"KKApp","startTime":"2018-02-06T21:38:32","portID":"01","ani":"9189280000","dnis":"8559281111","ctiCallID":"01"}</code></p>
  
  <p>I am trying something like this:</p>
  
  <p>....</p>
  
  <pre><code>try{
      JSONObject obj = new JSONObject();
      obj.put("machineName",machineName);
      obj.put("appName", appName);
      obj.put("startTime", formattedCurrentDate);
      obj.put("portID",portID);
      obj.put("ani",ani);
      obj.put("dnis", dnis);
      obj.put("ctiCallID", ctiCallID);
  
      String strobj = obj.toString();
  
      String uri = wsUri+"/StartCall?";
  
      HttpClient client = new HttpClient();
      client.getParams().setConnectionManagerTimeout(1300);
      client.getParams().setSoTimeout(13000);
  
      PostMethod method = new PostMethod(uri);
      method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      method.setQueryString("parameter="+strobj );
  
      int statusCode = client.executeMethod(method);
  
      byte[] responseBody = method.getResponseBody();
      output = new String(responseBody);
  }
  </code></pre>
  
  <p>....</p>
  
  <p>But I am getting an "Invalid URI" at runtime. It doesn't seem to like the query parameter being a json string. I read somewhere about encoding the json string ... Do I somehow need to encode the json string?</p>