FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
realtime-market-data-api/example/java/HttpJavaExample.java at main · infoway-api/realtime-market-data-api · GitHub
infoway-api
/
realtime-market-data-api
Public
Notifications
You must be signed in to change notification settings
Fork
31
Star
278
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
realtime-market-data-api
/
example
/
java
/
HttpJavaExample.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (42 loc) · 1.75 KB
Breadcrumbs
realtime-market-data-api
/
example
/
java
/
HttpJavaExample.java
Copy path
File metadata and controls
54 lines (42 loc) · 1.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStreamReader
;
import
java
.
net
.
HttpURLConnection
;
import
java
.
net
.
URL
;
public
class
HttpExample
{
public
static
void
main
(
String
[]
args
) {
try
{
// 定义请求URL
String
apiUrl
=
"https://data.infoway.io/stock/batch_kline/1/10/002594.SZ%2C00285.HK%2CTSLA.US"
;
URL
url
=
new
URL
(
apiUrl
);
// 创建HTTP连接
HttpURLConnection
connection
= (
HttpURLConnection
)
url
.
openConnection
();
// 设置请求方法为GET
connection
.
setRequestMethod
(
"GET"
);
// 设置请求头(可选)
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/5.0"
);
connection
.
setRequestProperty
(
"Accept"
,
"application/json"
);
connection
.
setRequestProperty
(
"apiKey"
,
"yourApikey"
);
// 获取响应码
int
responseCode
=
connection
.
getResponseCode
();
System
.
out
.
println
(
"HTTP code: "
+
responseCode
);
// 读取响应内容
BufferedReader
reader
;
if
(
responseCode
==
HttpURLConnection
.
HTTP_OK
) {
reader
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
}
else
{
reader
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getErrorStream
()));
}
String
line
;
StringBuilder
response
=
new
StringBuilder
();
while
((
line
=
reader
.
readLine
()) !=
null
) {
response
.
append
(
line
);
}
reader
.
close
();
// 打印响应内容
System
.
out
.
println
(
"message: "
+
response
);
}
catch
(
IOException
e
) {
e
.
printStackTrace
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL