title: Adding value to path parameter in Java REST?
body: <pre><code>NOTICE UPDATE!!
  
  The problem got solved and i added my own answer in the thread
  </code></pre>
  
  <p>In short, I have attempted to add the parameter "scan_id" value but since it is a POST i can't add the value directly in the url path.</p>
  
  <p>using the code i already have, how would i go about modifying or adding so that the url is correct, that is, so that it accepts my POST?.</p>
  
  <p>somehow i have been unable to find any examples that have helped me in figuring out how i would go about doing this..</p>
  
  <p>I know how to do a POST with a payload, a GET with params. but a post with Params is very confusing to me.</p>
  
  <p>Appreciate any help. (i'd like to continue using HttpUrlConnection unless an other example is provided that also tells me how to send the request and not only configuring the path.</p>
  
  <p>I've tried adding it to the payload.
  I've tried UriBuilder but found it confusing and in contrast with the rest of my code, so wanted to ask for help with HttpUrlConnection.</p>
  
  <pre><code>URL url = new URL("http://localhost/scans/{scan_id}/launch");
  HttpURLConnection con = (HttpURLConnection) url.openConnection();
          con.setRequestMethod("POST");
          con.setRequestProperty("tmp_value_dont_mind_this", "432432");
          con.setRequestProperty("X-Cookie", "token=" + "43432");
          con.setRequestProperty("X-ApiKeys", "accessKey="+"43234;" + " secretKey="+"43234;");
  
          con.setDoInput(true);
          con.setDoOutput(true); //NOT NEEDED FOR GETS
          con.setRequestMethod("POST");
          con.setRequestProperty("Accept", "application/json");
          con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  
                  //First example of writing (works when writing a payload)
          OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream(), "UTF-8");
          writer.write(payload);
          writer.close();     
  
          //second attemp at writing, doens't work (wanted to replace {scan_id} in the url)
          DataOutputStream writer = new DataOutputStream(con.getOutputStream());
          writer.writeChars("scan_id=42324"); //tried writing directly
          //writer.write(payload);
          writer.close();     
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost/scans/launch
  </code></pre>
  
  <p>I'd like one of the three response codes because then i know the Url is correct:</p>
  
  <pre><code>200 Returned if the scan was successfully launched. 
  403 Returned if the scan is disabled. 
  404 Returned if the scan does not exist. 
  </code></pre>
  
  <p>I've tried several urls </p>
  
  <pre><code>localhost/scans/launch, 
  localhost/scans//launch, 
  localhost/scans/?/launch, 
  localhost/scans/{scan_id}/launch,
  </code></pre>