takes a URL string, turns it into a Java URL object - then prints the different parts of that URL
URL = a Java object for a web address
the program breaks the address into parts like protocol, host, path, query, and fragment
Output:
URL is https://www.amrood.com/index.htm?language=en#j2se
protocol is https
authority is www.amrood.com
file name is /index.htm?language=en
host is www.amrood.com
path is /index.htm
port is -1
default port is 443
query is language=en
ref is j2se
Main points to remember:
url.openConnection() // opens the connection.
setRequestMethod("POST") // makes it a POST request.
setDoOutput(true) // allows sending data.
getOutputStream() // is where you write the POST data.
getResponseCode() // gets the server status.
getInputStream() // reads the server response.
Simple Memory pattern:
Open connection
Set POST
Turn output on
Write data
Get response code
Read response
another .... Quick memory version:
getHttpClient() gets the client
new HttpPost(url) creates the POST request
URLEncodedUtils.parse(...) splits the parameter string into form data
setEntity(...) puts the data into the request
client.execute(request) sends it
getStatusLine().getStatusCode() gets the response code
Pattern to remember:
Create client
Create POST
Parse params
Set entity
Execute request
Read response
first task... to see the post data in RequestBins inspect window (just use the default settings here, post data will show up under trigger, export, event) you'll have to tell the server there you're a html form (using the http header).
I had to add httpcore and apache commons logging to make it build:
https://mvnrepository.com/artifact/commons-logging/commons-logging/1.2
https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore/4.4.10
GO TO FULL VERSION