How to Get a new HttpURLConnection

public URLConnection openConnection () was added in API level 1
Returns a new connection to the resource referred to by this URL.
Throws: IOException - if an error occurs while opening the connection.

1. Create a new URL object named myUrl.

2. Declare a new HttpURLConnection named myHttpURLConnection.
3. In the MainActivity.java file, add the below line to the imports section. 

import java.io.IOException;

4. Add the below catch statement under the MalformedURLException catch you created when you created the URL object.

catch (IOException e) { 
e.printStackTrace();
//Toast.makeText(this, "URL:No I/O Exception", Toast.LENGTH_LONG).show();
}

5. Add the below line in the try/catch right after you create your URL named myUrl above(in step #1). This must be in the try/catch statement.

myHttpURLConnection = (HttpURLConnection) myUrl.openConnection();

6. Compile and run!

Next Recommended Article: How to Get the Response Code Returned by a Remote HTTP server

Resources:
http://developer.android.com/reference/java/net/HttpURLConnection.html
http://stackoverflow.com/questions/16122999/java-urlconnection-when-do-i-need-to-use-the-connect-method
https://www.tbray.org/ongoing/When/201x/2012/01/17/HttpURLConnection