title: 404 Error in accessing https URL - Java , but working fine with POSTMAN or SOAPUI
body: <p><strong>Edit on 21st Nov :</strong> I have tried in accessing the URL directly using browser, it gives me the same 404 error response. But while checking in POSTMAN - code , i could see the call goes as below. So can someone please let me know how to send the call in sameway? thanks</p>
  
  <p>POST /api/test/PW/authentication/user
   HTTP/1.1</p>
  
  <p>Host: www.hostname.com
  X-API-Key: saksj82kqjsak290d </p>
  
  <p>cache-control: no-cache</p>
  
  <p>Postman-Token: 2b7fl871-195a-4782-9000-6ce269242704</p>
  
  <p>Content-Type: multipart/form-data;boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW</p>
  
  <p>Content-Disposition: form-data; name="credential"</p>
  
  <p>user123</p>
  
  <p>Content-Disposition: form-data; name="password"</p>
  
  <p>pass123
  ------WebKitFormBoundary7MA4YWxkTrZu0gW--</p>
  
  <p><strong>Original Message :</strong> 
  I have an issue while fetching token from a https Rest APi using Java code.
  Request URL : <strong><a href="https://www.hostname.com/api/test/PW/authentication/user" rel="nofollow noreferrer">https://www.hostname.com/api/test/PW/authentication/user</a></strong>
  Curl : 
  <strong>curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --header 'ApiKey: saksj82kqjsak290d -d 'userid=user123&amp;password=pass123' '<a href="https://www.hostname.com/api/test/PW/authentication/user" rel="nofollow noreferrer">https://www.hostname.com/api/test/PW/authentication/user</a>'</strong>
  Method : POST</p>
  
  <p>Once i send Post reqyest i will get the Token in Header values in JSON format. But while pinging the server i am getting 404 rsponse from Java. But with POSTMAN tool, i am getting the response as 200 with proper token in response header data.</p>
  
  <p>Note : i have changed the URL here to some dummy.</p>
  
  <p>So far i have tried as below and not sure where i have gone wrong.</p>
  
  <pre><code>                    import java.net.*;
                  import java.io.*;
                  import java.util.*;
                  import java.io.BufferedReader;
                  import java.io.DataOutputStream;
                  import java.io.IOException;
                  import java.io.InputStreamReader;
                  import java.io.UnsupportedEncodingException;
                  import java.net.CookieHandler;
                  import java.net.CookieManager;
  
                  import java.net.URL;
                  import java.net.URLEncoder;
                  import java.util.ArrayList;
                  import java.util.List;
  
                  import java.util.Set;
                  import java.net.HttpuConnection;
  
                  import javax.net.ssl.HttpsuConnection;
                  import java.lang.annotation.Retention;
                  import java.net.MalformedURLException;
  
                  public class Tokenhttps {
                      public static void main(String[] args) throws MalformedURLException {
  
                          int code;
  
                          String httpsurl = "https://www.hostname.com/api/test/PW/authentication/user";
  
                          String KeytoPass = "saksj82kqjsak290d";
  
                          try{
                                URL httpurl = new URL(httpsurl);
                                HttpuConnection uConnect = (HttpuConnection) httpurl.openConnection();
  
                              //Set header
                                uConnect.setDoOutput(true);
                                uConnect.setRequestMethod("POST");
                                urlConnect.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
                                uConnect.setRequestProperty("Accept", "application/json");
                                uConnect.setRequestProperty("ApiKey", KeytoPass);
  
                              //Set body
                                String bodydata ="{\"userid\":\"user123\",\"password\":\"pass123\"}";
  
                              //POST
                              DataOutputStream  dos = new DataOutputStream (uConnect.getOutputStream ());
                              dos.write(bodydata.getBytes());
                              dos.flush();
  
                              // Read the response.
                              InputStreamReader isr = null;
                              code = uConnect.getResponseCode();
                            System.out.println("responseCode:" + code );
                              if (code == 200) {
                                  System.out.println("Connection is Success" );
                                 isr = new InputStreamReader(uConnect.getInputStream());
                               //Print Header Fields
                                    System.out.println("HeaderValues :"+uConnect.getHeaderFields ());
                                                  } 
                             else {
                                 isr = new InputStreamReader(uConnect.getErrorStream());
                              }
                          }
  
                           catch(Exception errormsg){
                            System.out.println("Error: " +errormsg);
                          }   
                      }
                  }
  </code></pre>