title: Send xml as part of URL request in Java
body: <p>This might be a trivial question but I'm trying to send web request to USPS to get a http post response (or email response depending on my request) containing the tracking information based on the tracking number that I send in. The documentation says the xml needs to appended as part of the url like below</p>
  
  <pre><code>http://secure.shippingapis.com/ShippingAPITest.dll?API=TrackV2&amp;XML=&lt;PTSEmailRequest USERID="xxxxx"&gt;&lt;TrackId&gt;xxxxx&lt;/TrackId&gt;&lt;RequestType&gt;EN&lt;/RequestType&gt;&lt;/PTSEmailRequest&gt;
  </code></pre>
  
  <p>I saw there were 2 ways to make an xml request, one using <code>HttpPost</code> and the other <code>URLConnection</code>. I'm a bit thrown by how I go about this and I'm failing to appreciate what's the difference between appending xml in the url and a normal http request. Can someone please clear things up for me? </p>
  
  <p>USPS documentation for tracking =>
  <a href="https://www.usps.com/business/web-tools-apis/track-and-confirm.pdf" rel="nofollow noreferrer">https://www.usps.com/business/web-tools-apis/track-and-confirm.pdf</a></p>
  
  <p>I read these related Stackoverflow posts<br/>
  <a href="https://stackoverflow.com/questions/5953631/java-how-to-send-a-xml-request">Java: How to send a XML request?</a><br/>
  <a href="https://stackoverflow.com/questions/2735839/posting-xml-request-in-java">posting XML request in java</a></p>
  
  <pre><code>HttpClient httpclient = HttpClients.createDefault();
  HttpPost httppost = new HttpPost("http://secure.shippingapis.com/ShippingAPITest.dll");
  
  List&lt;String&gt; params = new ArrayList&lt;String&gt;(2);
  params.add(new BasicNameValuePair("API", "TrackV2"));
  params.add(new BasicNameValuePair("XML", FuncTOGenerateXML()));
  httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
  
  HttpResponse response = httpclient.execute(httppost);
  HttpEntity entity = response.getEntity();
  
  if (entity != null) {
      InputStream instream = entity.getContent();
      //.....
      // .....
      instream.close();
  }
  </code></pre>