curl 命令:
curl -i -X GET http://locahost:29976:8001/apis
java代码:
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"); } }
这样就好了