http请求digest auth认证
http请求digest auth认证
1.post请求 public static String postMethod(String url, String query,String host) throws IOException {String content = null;//认证CloseableHttpClient httpclient=digestAuth(host);try {HttpPost postMethod = new HttpPost(url);StringEntity s = new StringEntity(query);s.setContentEncoding("utf-8");//编码s.setContentType("application/xml");postMethod.setEntity(s);HttpResponse response = httpclient.execute(postMethod);content = EntityUtils.toString(response.getEntity());} catch (Exception e) {System.out.println("推送失败:" + e);} finally {httpclient.close();}return content; }2.byte[]类型参数 public static String postMethodAnalysisImage(String url, byte[] binaryStreamsStr,String host) throws IOException {CloseableHttpClient httpclient=digestAuth(host);String content=null;try {HttpPost postMethod = new HttpPost(url);HttpEntity reqEntity = new ByteArrayEntity(binaryStreamsStr, ContentType.APPLICATION_JSON);postMethod.setEntity(reqEntity);StringEntity s = new StringEntity(reqEntity.toString());s.setContentEncoding("utf-8");//编码postMethod.setEntity(s);postMethod.setEntity(reqEntity);HttpResponse response = httpclient.execute(postMethod);content = EntityUtils.toString(response.getEntity());} catch (Exception e) {System.out.println("推送失败:" + e);}finally {httpclient.close();}return content; } 3.HttpGet 请求 public static String getMethodFDLib(String url, String host) throws IOException {String content = null;CloseableHttpClient httpclient=digestAuth(host);try {HttpGet getMethod = new HttpGet(url);org.apache.http.HttpResponse response = httpclient.execute(getMethod);content = EntityUtils.toString(response.getEntity());} catch (Exception e) {System.out.println("推送失败:" + e);}finally {httpclient.close();}return content; }
private static CloseableHttpClient digestAuth(String host) {CredentialsProvider credsProvider = new BasicCredentialsProvider();credsProvider.setCredentials(new AuthScope(host, 80),//请求地址 + 端口号密码2b3e201690"));// 用户名 + 密码 (用于验证)CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();return httpclient; }
最新文章
- 网络命令(ARP、PING)的使用分析
- 非诚勿扰24灯全灭php,收二手货小伙上非诚勿扰,24盏灯全灭还遭羞辱,最后才知道是收二手豪车身价上亿...
- dump文件深度分析
- 哀悼日设置网站主题为黑白主题
- java文件下载错误提示
- css中text文字超出宽度省略号显示并鼠标悬停显示剩余全部:
- 文本长度过长时隐藏并显示省略号“...”,以及鼠标停留时悬浮显示全部文本(兼容IE)
- 50+ Best Unity Assets: Shader, Editor Extensions, Level Editors, Models, Terrain
- mmap函数使用
- 软件构造复习小结(2)——设计规约(Specification)
- 针对ONION勒索病毒!如何关闭139端口及445端口等危险端口
- 路在何方?前途迷茫,去不去HP?
- TCPIP和TCP,UDP
- Hashtable的原理
- Visul C++中CList用法
- 1637
- SQL语句注入的全过程