Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AplikacjaALX
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
AplikacjaALX
Commits
279664db
Commit
279664db
authored
May 10, 2024
by
patryk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pobieranie Stringa
parent
b78ef561
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
Pobieranie3_HttpClient_String.java
src/main/java/pobieranie/Pobieranie3_HttpClient_String.java
+36
-0
No files found.
src/main/java/pobieranie/Pobieranie3_HttpClient_String.java
0 → 100644
View file @
279664db
package
pobieranie
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.net.http.HttpClient
;
import
java.net.http.HttpRequest
;
import
java.net.http.HttpResponse
;
import
java.net.http.HttpResponse.BodyHandlers
;
public
class
Pobieranie3_HttpClient_String
{
public
static
void
main
(
String
[]
args
)
{
final
String
adres
=
"http://api.nbp.pl/api/exchangerates/tables/A/?format=json"
;
// spróbuj xml
try
{
URI
uri
=
new
URI
(
adres
);
HttpClient
client
=
HttpClient
.
newHttpClient
();
HttpRequest
request
=
HttpRequest
.
newBuilder
(
uri
).
build
();
HttpResponse
<
String
>
response
=
client
.
send
(
request
,
BodyHandlers
.
ofString
());
System
.
out
.
println
(
"response: "
+
response
);
System
.
out
.
println
(
"status: "
+
response
.
statusCode
());
System
.
out
.
println
(
"Content-Type: "
+
response
.
headers
().
firstValue
(
"content-type"
).
orElse
(
"--"
));
// if(response.statusCode() != 200) {
// return;
// }
// body jest takiego typu, jaki wynika z użytego BodyHandler
String
body
=
response
.
body
();
System
.
out
.
println
(
"Długość stringa: "
+
body
.
length
());
System
.
out
.
println
(
body
);
}
catch
(
IOException
|
URISyntaxException
|
InterruptedException
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