【发布时间】:2020-10-07 03:34:55
【问题描述】:
我一直在尝试使用 java 访问带有以下请求标头示例的 api
curl -X GET -k --header "x-apikey: accesskey=4def6bc216f14c1ab86dfba8738ff4a5; secretkey=a47d1d3a071443449a75821129526b96" https://Tenable.sc/rest/currentUser***`***
像这样
URL urlcon= new URL("https://Tenable.sc/rest/currentUser");
HttpsURLConnection connection = (HttpsURLConnection) urlcon.openConnection();
connection.setRequestMethod("GET");
String apiKey = "accesskey:4def6bc216f14c1ab86dfba8738ff4a5; secretkey:a47d1d3a071443449a75821129526b96;";
connection.setRequestProperty("x-apikey", apiKey);
System.out.println(connection.getResponseCode());
我可以知道如何将上面的 curl 请求示例转换为 http 请求的标头吗?
【问题讨论】:
标签: java api curl http-headers httprequest