get方式的API怎麼呼叫
- 2022-09-06
Java例項
public static void main(String[] args) {
String host = “http://jisukdcx。market。alicloudapi。com”;
String path = “/express/query”;
String method = “GET”;
String appcode = “你自己的AppCode”;
Map
//最後在header中的格式(中間是英文空格)為Authorization:APPCODE
83359fd73fe94948385f570e3c139105
headers。put(“Authorization”, “APPCODE ” + appcode);
Map
querys。put(“number”, “1202516745301”);
querys。put(“type”, “YUNDA”);
try { /** * 重要提示如下: * HttpUtils請從 * https://github。com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils。java * 下載 * * 相應的依賴請參照 * https://github。com/aliyun/api-gateway-demo-sign-java/blob/master/pom。xml
*/
HttpResponse response = HttpUtils。doGet(host, path, method, headers, querys);
System。out。println(response。toString());
//獲取response的body
//System。out。println(EntityUtils。toString(response。getEntity()));
}
catch (Exception e) { e。printStackTrace(); }
}