Hi,今天写篇关于 七牛-日志下载 的博文
文档可参考:https://developer.qiniu.com/fusion/api/1226/download-the-log
本质上是个发送HTTP POST请求的过程
POST /v2/tune/log/list
Host: fusion.qiniuapi.com
Content-Type: application/json
{“domains”:”petertest.qiniuts.com”,”day”:”2018-08-03”}
JAVA:
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.Gson;
import com.qiniu.http.Client;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
public class Download_the_log {
public static void main(String[] args) throws IOException {
Gson gson = new Gson();
Map<String, String> m = new HashMap<>();
m.put("day", "2018-08-03");
m.put("domains","petertest.qiniuts.com");
String paraR = gson.toJson(m);
byte[] bodyByte = paraR.getBytes();
String url = "http://fusion.qiniuapi.com/v2/tune/log/list";
String accessKey = "";
String secretKey = "";
Auth auth = Auth.create(accessKey, secretKey);
String accessToken = (String) auth.authorizationV2(url, "POST", bodyByte, "application/json").get("Authorization");
System.out.println(accessToken);
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);
System.out.println(resp.toString());
System.out.println(resp.bodyString());
} catch (Exception e) {
e.printStackTrace();
}
}
}