Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
sockets
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
DAI 26-27
sockets
Commits
f2fe0ec0
Commit
f2fe0ec0
authored
Sep 21, 2026
by
Miguel Reboiro-Jato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds HttpClient example
parent
47991f77
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
18 deletions
+45
-18
ESEIHomeDownload.java
.../es/uvigo/esei/dai/sockets/example5/ESEIHomeDownload.java
+14
-18
ESEIHomeDownload.java
.../es/uvigo/esei/dai/sockets/example6/ESEIHomeDownload.java
+31
-0
No files found.
src/main/java/es/uvigo/esei/dai/sockets/example5/ESEIHomeDownload.java
View file @
f2fe0ec0
...
@@ -21,30 +21,26 @@
...
@@ -21,30 +21,26 @@
*/
*/
package
es
.
uvigo
.
esei
.
dai
.
sockets
.
example5
;
package
es
.
uvigo
.
esei
.
dai
.
sockets
.
example5
;
import
java.io.BufferedReader
;
import
java.net.URI
;
import
java.io.IOException
;
import
java.net.http.HttpClient
;
import
java.io.InputStreamReader
;
import
java.net.http.HttpRequest
;
import
java.net.MalformedURLException
;
import
java.net.http.HttpResponse
;
import
java.net.URL
;
import
java.net.URLConnection
;
public
class
ESEIHomeDownload
{
public
class
ESEIHomeDownload
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
try
{
try
{
final
URL
url
=
new
URL
(
"https://www.esei.uvigo.es"
);
final
HttpClient
client
=
HttpClient
.
newHttpClient
(
);
final
URLConnection
connection
=
url
.
openConnection
();
final
HttpRequest
request
=
HttpRequest
.
newBuilder
()
System
.
out
.
println
(
connection
.
getClass
());
.
uri
(
URI
.
create
(
"https://esei.uvigo.es"
))
.
GET
()
.
build
();
try
(
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
())))
{
final
HttpResponse
<
String
>
response
=
client
String
line
;
.
send
(
request
,
HttpResponse
.
BodyHandlers
.
ofString
());
while
((
line
=
br
.
readLine
())
!=
null
)
{
System
.
out
.
println
(
line
);
System
.
out
.
println
(
response
.
body
());
}
}
catch
(
final
Exception
e
)
{
}
}
catch
(
final
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
catch
(
final
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
...
...
src/main/java/es/uvigo/esei/dai/sockets/example6/ESEIHomeDownload.java
0 → 100644
View file @
f2fe0ec0
package
es
.
uvigo
.
esei
.
dai
.
sockets
.
example6
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
public
class
ESEIHomeDownload
{
public
static
void
main
(
String
[]
args
)
{
try
{
final
URL
url
=
new
URL
(
"https://www.esei.uvigo.es"
);
final
URLConnection
connection
=
url
.
openConnection
();
System
.
out
.
println
(
connection
.
getClass
());
try
(
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
())))
{
String
line
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
System
.
out
.
println
(
line
);
}
}
}
catch
(
final
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
catch
(
final
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment