https://blog.youkuaiyun.com/u012045045/article/details/100062035
private static String Post1(String url, String hexString) throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost get = new HttpPost(url);
StringEntity stringEntity = new StringEntity("json="+hexString);
stringEntity.setContentType("application/x-www-form-urlencoded");
get.setEntity(stringEntity);
ProtocolVersion protocolVersion = get.getProtocolVersion();
System.out.println(protocolVersion.getProtocol());
try {
//该网页需要认证(用户名、密码)
HttpClientContext context = new HttpClientContext();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
context.setCredentialsProvider(credentialsProvider);
CloseableHttpResponse execute = client.execute(get, context);
//----以下一样
HttpEntity entity = execute.getEntity();
InputStream in = entity.getContent();
StringBuilder builder = new StringBuilder();
BufferedReader bufreader = new BufferedReader(new InputStreamReader(in));
for (String temp = bufreader.readLine(); temp != null; temp = bufreader.readLine()) {
builder.append(temp);
}
return builder.toString();
} catch (ClientProtocolException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}