CodeGym /Courses /Java Collections /Tasks | Level 10 | Lesson 4

Tasks | Level 10 | Lesson 4

Java Collections
Level 10 , Lesson 4
Available
10
Task
Java Collections, level 10, lesson 4
Locked
POST, not GET
POST, not GET
20
Task
Java Collections, level 10, lesson 4
Locked
Again, POST, not GET
Again, POST, not GET
10
Task
Java Collections, level 10, lesson 4
Locked
Error codes
Error codes
10
Task
Java Collections, level 10, lesson 4
Locked
URL properties
URL properties
Comments (9)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Hoist Level 17, San Diego, United States
24 April 2026
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
Hoist Level 17, San Diego, United States
24 April 2026
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
matemate123 Level 50, Kraków, Poland
13 December 2023
Too small amount introduction into topic
Lisa Level 41
14 February 2022
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).

        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
Andrei Level 41
5 August 2021
I didn't like these tasks, I found them much more difficult compared with the information provided up to them.
fzw Level 41, West University Place, United States
15 May 2020
URL properties: do not re-throw exception, otherwise it will not pass validator
Senned Level 41, Azov, Russia
22 January 2020
For second task dowloand from Maven org.apache.httpcomponents:httpclient:4.5 or higher
Olek Level 41, Amsterdam, Netherlands
4 February 2020
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
Andrei Level 41
5 August 2021
https://jar-download.com/artifacts/org.apache.httpcomponents/httpclient