curl 命令:java
curl -i -X GET http://locahost:29976:8001/apisapi
java代碼:curl
public static void listApiTest() throws Exception { CloseableHttpClient client = HttpClients.createDefault(); String url = "http://192.168.1.45:29976/apis"; HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String message = EntityUtils.toString(entity, "UTF-8"); System.out.println(message); }else { System.out.println("error"); } }
這樣就行了url