Skip to content

Commit

Permalink
异步抓取接口
Browse files Browse the repository at this point in the history
  • Loading branch information
neikochan committed Jul 17, 2018
1 parent 13ed3de commit 69f9ffe
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions examples/FetchApiDemo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.fusion;
package com.examples;

import com.google.gson.Gson;
import com.qiniu.http.Client;
Expand All @@ -13,28 +13,25 @@ public class FetchApiDemo {

protected static final org.slf4j.Logger logger = LoggerFactory.getLogger(FetchApiDemo.class);

public static void main(String[] args) throws Exception {

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);

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);
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();
logger.info(accessToken);
Expand Down

0 comments on commit 69f9ffe

Please sign in to comment.