title: HTTP Request with passing User and Password
body: <p>I'm currently working on an HTTP Request and it worked pretty good so far,
  now there is an Authentication Window and I'd like to know how to pass 
  Username and Password without adding an external jar like the Appache HTTP Client.</p>
  
  <p>The Basic Authentication with</p>
  
  <p><code>username:password@exampleUrl.com</code>
  didn't work.</p>
  
  <p>My Code so far:</p>
  
  <pre><code>private String[][] content;
  
  public String[][] sendRequest(String urlPart) {
  
      try {
  
          String url = "http://exampleurl.com"+urlPart; 
  
          URL obj = new URL(url);
          HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  
          BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
          String inputLine;
          StringBuffer response = new StringBuffer();
          while ((inputLine = in.readLine()) != null) {
              response.append(inputLine);
          }
          in.close();
  
  
          //convert response 
          JSONObject myresponse = new JSONObject(response.toString());
          JSONObject d_object = new JSONObject(myresponse.getJSONObject("d").toString());
          JSONArray results = new JSONArray(d_object.getJSONArray("results").toString());
  
          content = new String[results.length()][2];
  
          for (int i = 0; i &lt; results.length(); i++) 
          {
  
              JSONObject stereo = results.getJSONObject(i);
              content[i][0] = stereo.getString("RET_NAME");
              content[i][1] = stereo.getString("RET_VALUE");
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      return content;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/7exjd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7exjd.png" alt="enter image description here"></a></p>