title: Https PUT request with user name and password which send the JSON file as a payload
body: <p>I am new to java. I have a URL, UserName, Password. I need to make a PUT HTTP request using the URL, UserName and Password.
  I have to send JSON file as a payload using the HTTP Put request to the system which can accept only JSON.</p>
  
  <p>I have searched in StackOverFlow and found few suggestions which can make a simple request to the URL without User name and Password. But our URL need to be authenticated to make a request.</p>
  
  <p>Code which i have used to make a HTTP request </p>
  
  <pre><code>public static void main (String args[]) throws IOException
   {
    String userPassword = "";
    String encoding = new String(Base64.encodeBase64(userPassword.getBytes()));
    URL url = new URL(URL);
    HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
    httpCon.setDoOutput(true);
    httpCon.setRequestMethod("PUT");
    httpCon.setRequestProperty("Authorization", "Basic "+encoding);
    OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
    out.write("Resource content");
    out.close();
    httpCon.getInputStream();
   }
  </code></pre>