FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-sdk/examples/FetchApiDemo.java at master · CDNCloud-com/java-sdk · GitHub
CDNCloud-com
/
java-sdk
Public
forked from
qiniu/java-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-sdk
/
examples
/
FetchApiDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (37 loc) · 1.46 KB
Breadcrumbs
java-sdk
/
examples
/
FetchApiDemo.java
Copy path
File metadata and controls
41 lines (37 loc) · 1.46 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
package
com
.
examples
;
import
com
.
google
.
gson
.
Gson
;
import
com
.
qiniu
.
http
.
Client
;
import
com
.
qiniu
.
util
.
Auth
;
import
com
.
qiniu
.
util
.
StringMap
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
public
class
FetchApiDemo
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//参考api文档 https://developer.qiniu.com/kodo/api/4097/asynch-fetch
//设置好账号的ACCESS_KEY和SECRET_KEY
String
ACCESS_KEY
=
"Access_Key"
;
String
SECRET_KEY
=
"Secret_Key"
;
//要上传的空间
String
bucketname
=
"Bucket_Name"
;
Auth
auth
=
Auth
.
create
(
ACCESS_KEY
,
SECRET_KEY
);
// 构造post请求body
Gson
gson
=
new
Gson
();
Map
<
String
,
String
>
m
=
new
HashMap
();
m
.
put
(
"url"
,
"http://chentaodb.qiniuts.com/1.jpg"
);
m
.
put
(
"bucket"
,
bucketname
);
String
paraR
=
gson
.
toJson
(
m
);
byte
[]
bodyByte
=
paraR
.
getBytes
();
// 获取签名
String
url
=
"http://api-z2.qiniu.com/sisyphus/fetch"
;
String
accessToken
= (
String
)
auth
.
authorizationV2
(
url
,
"POST"
,
bodyByte
,
"application/json"
)
.
get
(
"Authorization"
);
Client
client
=
new
Client
();
StringMap
headers
=
new
StringMap
();
headers
.
put
(
"Authorization"
,
accessToken
);
try
{
com
.
qiniu
.
http
.
Response
resp
=
client
.
post
(
url
,
bodyByte
,
headers
,
Client
.
JsonMime
);
}
catch
(
Exception
e
) {
throw
new
Exception
(
e
.
getMessage
());
}
}
}
Back
|
FazBrowse Home
|
New Git URL