0
你好是一個開始於Java世界的開發人員我想知道如何在Java中編寫這個curl的等價物。如何在Java中創建https帖子?
curl -x POST \ -H "Authorization:Basic Sisi" \ -d "grant_type=client_credentials" \ "https://api.orange.com/oauth/v2/token"
你好是一個開始於Java世界的開發人員我想知道如何在Java中編寫這個curl的等價物。如何在Java中創建https帖子?
curl -x POST \ -H "Authorization:Basic Sisi" \ -d "grant_type=client_credentials" \ "https://api.orange.com/oauth/v2/token"
您可以使用Apache HttpClient在java中實現它。
一個例子是 -
String url = "https://api.orange.com/oauth/v2/token";
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
post.setHeader("Authorization", "Basic Sisi");
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer result = new StringBuffer();
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
//Print result
在這裏閱讀更多 - http://www.mkyong.com/java/apache-httpclient-examples/
非常感謝你 –