HttpClient详解
HttpClient:是一个接口
首先需要先创建一个DefaultHttpClient的实例
HttpClient httpClient=new DefaultHttpClient();
发送GET请求:
先创建一个HttpGet对象,传入目标的网络地址,然后调用HttpClient的execute()方法即可:
HttpGet HttpGet=new HttpGet(“http://www.baidu.com”);
httpClient.execute(httpGet);
发送POST请求:
创建一个HttpPost对象,传入目标的网络地址:
HttpPost httpPost=new HttpPost(“http://www.baidu.com”);
通过一个NameValuePair集合来存放待提交的参数,并将这个参数集合传入到一个UrlEncodedFormEntity中,然后调用HttpPost的setEntity()方法将构建好的UrlEncodedFormEntity传入:
List<NameValuePair>params=newArrayList<NameValuePair>();
Params.add(new BasicNameValuePair(“username”,”admin”));
Params.add(new BasicNameValuePair(“password”,”123456”));
UrlEncodedFormEntity entity=newUrlEncodedFormEntity(params,”utf-8”);
httpPost.setEntity(entity);
调用HttpClient的execute()方法,并将HttpPost对象传入即可:
HttpClient.execute(HttpPost);
执行execute()方法之后会返回一个HttpResponse对象,服务器所返回的所有信息就保护在HttpResponse里面.
先取出服务器返回的状态码,如果等于200就说明请求和响应都成功了:
If(httpResponse.getStatusLine().getStatusCode()==200){
//请求和响应都成功了
HttpEntityentity=HttpResponse.getEntity();//调用getEntity()方法获取到一个HttpEntity实例
Stringresponse=EntityUtils.toString(entity,”utf-8”);//用EntityUtils.toString()这个静态方法将HttpEntity转换成字符串,防止服务器返回的数据带有中文,所以在转换的时候将字符集指定成utf-8就可以了
}
Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户端发送Http请求变得容易,而且也方便了开发人员测试接口(基于Http协议的),即提高了开发的效率,也方便提高代码的健壮性。因此熟练掌握HttpClient是很重要的必修内容,掌握HttpClient后,相信对于Http协议的了解会更加深入。
一、简介
HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。HttpClient已经应用在很多的项目中,比如Apache Jakarta上很著名的另外两个开源项目Cactus和HTMLUnit都使用了HttpClient。
下载地址: http://hc.apache.org/downloads.cgi
二、特性
1. 基于标准、纯净的Java语言。实现了Http1.0和Http1.1
2. 以可扩展的面向对象的结构实现了Http全部的方法(GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE)。
3. 支持HTTPS协议。
4. 通过Http代理建立透明的连接。
5. 利用CONNECT方法通过Http代理建立隧道的https连接。
6. Basic, Digest, NTLMv1, NTLMv2, NTLM2 Session, SNPNEGO/Kerberos认证方案。
7. 插件式的自定义认证方案。
8. 便携可靠的套接字工厂使它更容易的使用第三方解决方案。
9. 连接管理器支持多线程应用。支持设置最大连接数,同时支持设置每个主机的最大连接数,发现并关闭过期的连接。
10. 自动处理Set-Cookie中的Cookie。
11. 插件式的自定义Cookie策略。
12. Request的输出流可以避免流中内容直接缓冲到socket服务器。
13. Response的输入流可以有效的从socket服务器直接读取相应内容。
14. 在http1.0和http1.1中利用KeepAlive保持持久连接。
15. 直接获取服务器发送的response code和 headers。
16. 设置连接超时的能力。
17. 实验性的支持http1.1 response caching。
18. 源代码基于Apache License 可免费获取。
三、使用方法
使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可。
1. 创建HttpClient对象。
2. 创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建HttpPost对象。
3. 如果需要发送请求参数,可调用HttpGet、HttpPost共同的setParams(HetpParams params)方法来添加请求参数;对于HttpPost对象而言,也可调用setEntity(HttpEntity entity)方法来设置请求参数。
4. 调用HttpClient对象的execute(HttpUriRequest request)发送请求,该方法返回一个HttpResponse。
5. 调用HttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取服务器的响应头;调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器的响应内容。程序可通过该对象获取服务器的响应内容。
6. 释放连接。无论执行方法是否成功,都必须释放连接
四、实例
上传文件实例92-147行
- package com.zlzf.channel.common.util;
- import java.io.BufferedReader;
- import java.io.ByteArrayOutputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.URL;
- import java.net.URLDecoder;
- import java.security.KeyManagementException;
- import java.security.NoSuchAlgorithmException;
- import java.security.cert.CertificateException;
- import java.security.cert.X509Certificate;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.zip.GZIPInputStream;
- import javax.net.ssl.HostnameVerifier;
- import javax.net.ssl.HttpsURLConnection;
- import javax.net.ssl.SSLContext;
- import javax.net.ssl.SSLSession;
- import javax.net.ssl.TrustManager;
- import javax.net.ssl.X509TrustManager;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.ParseException;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.mime.MultipartEntityBuilder;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.util.EntityUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- /**
- * @Description: https客户端
- * @author syuf
- * @date 2017年8月1日 下午4:13:04
- */
- public class HttpsClientUtil {
- private static final Logger LOG = LoggerFactory.getLogger(HttpsClientUtil.class);
- private static final String ENC_UTF8 = "UTF-8";
- private static final String ENC_GBK = "GBK";
- /**
- * 默认的http连接超时时间
- */
- private final static int DEFAULT_CONN_TIMEOUT = 10000; // 10s
- /**
- * 默认的http read超时时间
- */
- private final static int DEFAULT_READ_TIMEOUT = 120000; // 120s
- private static class MyTrustManager implements X509TrustManager {
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- }
- public X509Certificate[] getAcceptedIssuers() {
- return new X509Certificate[] {};
- }
- }
- private static class TrustAnyHostnameVerifier implements HostnameVerifier {
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
- }
- /**
- * @Description: 上传文件
- * @param url 请求地址
- * @param fileParamName 上传文件的参数名称
- * @param file 文件内容
- * @param otherParams 其他 参数
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年3月1日 上午11:32:13
- */
- public static String uploadFile(String url,String fileParamName,File file, Map<String, String> otherParams) {
- return uploadFile(url, fileParamName, file, otherParams, "UTF-8");
- }
- /**
- * @Description: 上传文件
- * @param url 请求地址
- * @param fileParamName 上传文件的参数名称
- * @param file 文件内容
- * @param otherParams 其他 参数
- * @param charset 字符集
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年3月1日 上午11:32:13
- */
- public static String uploadFile(String url,String fileParamName,File file, Map<String, String> otherParams,String charset) {
- HttpEntity resEntity = null;
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, new TrustManager[] { new MyTrustManager() }, new java.security.SecureRandom());
- HttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new TrustAnyHostnameVerifier()).setSSLContext(sc).build();
- HttpPost httpPost = new HttpPost(url);
- MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
- for(Map.Entry<String, String> entry : otherParams.entrySet()){
- multipartEntityBuilder.addTextBody(entry.getKey(), entry.getValue());
- }
- multipartEntityBuilder.addBinaryBody(fileParamName, file);
- HttpEntity reqEntity = multipartEntityBuilder.build();
- httpPost.setEntity(reqEntity);
- HttpResponse response = httpClient.execute(httpPost);
- if(response.getStatusLine().getStatusCode() != 200){
- LOG.warn("[HttpsClient 上传文件]请求失败,statusCode={}",response.getStatusLine().getStatusCode());
- return null;
- }
- resEntity = response.getEntity();
- if (resEntity == null) {
- LOG.warn("[HttpsClient 上传文件]请求失败,resEntity is null.");
- return null;
- }
- return EntityUtils.toString(response.getEntity(),charset);
- } catch (KeyManagementException e) {
- LOG.error("[HttpsClient 上传文件]NoSuchAlgorithmException.",e);
- } catch (NoSuchAlgorithmException e) {
- LOG.error("[HttpsClient 上传文件]NoSuchAlgorithmException.",e);
- } catch (ClientProtocolException e) {
- LOG.error("[HttpsClient 上传文件]ClientProtocolException.",e);
- } catch (ParseException e) {
- LOG.error("[HttpsClient 上传文件]ParseException.",e);
- } catch (IOException e) {
- LOG.error("[HttpsClient 上传文件]IOException.",e);
- } finally {
- try {
- EntityUtils.consume(resEntity);
- } catch (IOException e) {
- LOG.error("[HttpsClient 上传文件]关闭流异常.",e);
- }
- }
- return null;
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param data 参数字符串
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月15日 下午3:47:03
- */
- public static String postZip(String url, String data) {
- return postZip(url, data, ENC_UTF8);
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param data 参数字符串
- * @param charset 字符集
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月15日 下午3:50:59
- */
- private static String postZip(String url, String data, String charset) {
- return postZip(url, data, charset, DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param paramsMap 参数map
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午8:37:22
- */
- public static String postZip(String url, Map<String, String> paramsMap) {
- return postZip(url, paramsMap, ENC_UTF8);
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param paramsMap 参数map
- * @param charset 字符集
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午8:35:57
- */
- public static String postZip(String url, Map<String, String> paramsMap, String charset) {
- return postZip(url, paramsMap, charset, DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param paramsMap 参数map
- * @param charset 字符集
- * @param connOut 链接超时时间
- * @param readOut 请求超时 时间
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午8:36:37
- */
- public static String postZip(String url, Map<String, String> paramMap, String charset, int connOut, int readOut) {
- return postZip(url, getParamStr(paramMap), charset, connOut, readOut);
- }
- /**
- * @Description: https协议 post zip
- * @param url 请求地址
- * @param paramData 参数数据
- * @param charset 字符集
- * @param connOut 链接超时时间
- * @param readOut 请求超时 时间
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午8:36:37
- */
- public static String postZip(String url, String paramData, String charset, int connOut, int readOut) {
- BufferedReader in = null;
- DataOutputStream out = null;
- HttpsURLConnection uc = null;
- StringBuffer sb = new StringBuffer();
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, new TrustManager[] { new MyTrustManager() }, new java.security.SecureRandom());
- uc = (HttpsURLConnection) new URL(url).openConnection();
- uc.setSSLSocketFactory(sc.getSocketFactory());
- uc.setHostnameVerifier(new TrustAnyHostnameVerifier());
- uc.setRequestMethod("POST");
- uc.setDoOutput(true);
- uc.setDoInput(true);
- uc.setUseCaches(false);
- uc.setConnectTimeout(connOut);
- uc.setReadTimeout(readOut);
- uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- uc.connect();
- out = new DataOutputStream(uc.getOutputStream());
- out.write(paramData.getBytes(charset));
- out.flush();
- out.close();
- in = new BufferedReader(new InputStreamReader(new GZIPInputStream(uc.getInputStream()), charset));
- String readLine = null;
- while ((readLine = in.readLine()) != null) {
- sb.append(readLine).append("\n");
- }
- } catch (Exception e) {
- LOG.error("[HttpsClient POST GZIP]请求异常", e);
- } finally {
- close(in, uc, null, out);
- }
- return sb.toString();
- }
- /**
- * @Description: HTTPS协议POST请求方法
- * @param url 请求地址
- * @param paramsMap 请求参数 map
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午12:30:39
- */
- public static String post(String url, Map<String, String> paramMap) {
- return post(url, paramMap, ENC_UTF8);
- }
- /**
- * @Description: HTTPS协议POST请求方法
- * @param url 请求地址
- * @param paramsMap 请求参数 map
- * @param charset 字符集
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2017年11月20日 下午5:02:08
- */
- public static String post(String url, Map<String, String> paramsMap, String charset) {
- return post(url, paramsMap, charset, DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
- /**
- * @Description: HTTPS协议POST请求方法
- * @param url 请求地址
- * @param paramsMap 参数map
- * @param charset 字符集
- * @param connOut 链接超时时间
- * @param readOut 响应超时时间
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午12:27:13
- */
- public static String post(String url, Map<String, String> paramMap, String charset, int connOut, int readOut) {
- return post(url, getParamStr(paramMap), charset, connOut, readOut);
- }
- /**
- * @Description: HTTPS协议POST请求方法
- * @param url 请求地址
- * @param param 参数字符串
- * @param charset 字符集
- * @param connOut 链接超时时间
- * @param readOut 响应超时时间
- * @return String 应答结果字符串
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午12:27:13
- */
- public static String post(String url, String param, String charset, int connOut, int readOut) {
- String result = null;
- BufferedReader in = null;
- DataOutputStream out = null;
- HttpsURLConnection uc = null;
- StringBuffer sb = new StringBuffer();
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, new TrustManager[] { new MyTrustManager() }, new java.security.SecureRandom());
- uc = (HttpsURLConnection) new URL(url).openConnection();
- uc.setSSLSocketFactory(sc.getSocketFactory());
- uc.setHostnameVerifier(new TrustAnyHostnameVerifier());
- uc.setRequestMethod("POST");
- uc.setDoOutput(true);
- uc.setDoInput(true);
- uc.setUseCaches(false);
- uc.setConnectTimeout(connOut);
- uc.setReadTimeout(readOut);
- uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- uc.connect();
- out = new DataOutputStream(uc.getOutputStream());
- out.write(param.getBytes(charset));
- out.flush();
- out.close();
- in = new BufferedReader(new InputStreamReader(uc.getInputStream(), charset));
- String readLine = null;
- while ((readLine = in.readLine()) != null) {
- sb.append(readLine).append("\n");
- }
- result = URLDecoder.decode(sb.toString(), charset);
- } catch (Exception e) {
- LOG.error("[HttpsClient POST]请求异常", e);
- } finally {
- close(in, uc, null, out);
- }
- return result;
- }
- /**
- * @Description: postFile
- * @param url 请求地址
- * @param data 请求参数
- * @return byte[] 二进制文件
- * @throws
- * @author: syuf
- * @date: 2018年1月16日 上午10:44:32
- */
- public static byte[] postFile(String url, String data) {
- return postFile(url, data, ENC_GBK);
- }
- /**
- * @Description: postFile
- * @param url 请求地址
- * @param data 请求参数
- * @param charset 字符集
- * @return byte[]二进制文件
- * @throws
- * @author: syuf
- * @date: 2018年1月16日 上午10:23:29
- */
- private static byte[] postFile(String url, String data, String charset) {
- return postFile(url, data, charset, DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
- /**
- * @Description: postFile
- * @param url 请求地址
- * @param data 请求参数
- * @param charset 字符集
- * @param connOut 连接超时时间
- * @param readOut 读取超时时间
- * @return byte []
- * @throws
- * @author: syuf
- * @date: 2018年1月16日 上午10:24:19
- */
- private static byte[] postFile(String url, String data, String charset, int connOut, int readOut) {
- byte[] btFile = null;
- BufferedReader in = null;
- DataOutputStream out = null;
- HttpsURLConnection uc = null;
- ByteArrayOutputStream outStream = null;
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, new TrustManager[] { new MyTrustManager() }, new java.security.SecureRandom());
- uc = (HttpsURLConnection) new URL(url).openConnection();
- uc.setSSLSocketFactory(sc.getSocketFactory());
- uc.setHostnameVerifier(new TrustAnyHostnameVerifier());
- uc.setRequestMethod("POST");
- uc.setDoOutput(true);
- uc.setDoInput(true);
- uc.setUseCaches(false);
- uc.setConnectTimeout(connOut);
- uc.setReadTimeout(readOut);
- uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- uc.connect();
- out = new DataOutputStream(uc.getOutputStream());
- out.write(data.getBytes(charset));
- out.flush();
- out.close();
- int respCode = uc.getResponseCode();
- if (respCode != 200) {
- in = new BufferedReader(new InputStreamReader(uc.getInputStream(), charset));
- StringBuilder sb = new StringBuilder();
- char[] buff = new char[2048];
- int cnt = 0;
- while ((cnt = in.read(buff)) != -1) {
- sb.append(buff, 0, cnt);
- }
- in.close();
- LOG.warn("[HttpsClient POST FILE]{}" , sb.toString());
- return null;
- }
- InputStream inStream = uc.getInputStream(); // 获取文件流二进制数据
- outStream = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int len = 0;
- while ((len = inStream.read(buffer)) != -1) {
- outStream.write(buffer, 0, len);
- }
- inStream.close();
- btFile = outStream.toByteArray();
- } catch (Exception e) {
- LOG.error("[HttpsClient POST FILE]请求异常", e);
- } finally {
- close(in, uc, null, outStream);
- }
- return btFile;
- }
- /**
- * @Description: HTTPS协议POST File请求方法
- * @param url 请求地址
- * @param paramsMap 参数map
- * @return byte[] 二进制文件
- * @throws
- * @author: syuf
- * @date: 2018年1月9日 下午8:14:11
- */
- public static byte[] postFile(String url, Map<String, String> paramsMap) {
- return postFile(url, paramsMap, ENC_UTF8);
- }
- /**
- * @Description: HTTPS协议POST File请求方法
- * @param url 请求地址
- * @param paramsMap 参数map
- * @param charset 字符集
- * @return byte[] 二进制文件
- * @throws
- * @author: syuf
- * @date: 2017年11月20日 下午5:06:03
- */
- public static byte[] postFile(String url, Map<String, String> paramsMap, String charset) {
- return postFile(url, getParamStr(paramsMap), charset, DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
- }
- /**
- * @Description: HTTP协议POST请求添加参数的封装方法
- * @param paramsMap 参数map
- * @return String 应答结果
- * @throws
- * @author: syuf
- * @date: 2017年11月20日 下午3:46:11
- */
- private static String getParamStr(Map<String, String> paramsMap) {
- StringBuffer param = new StringBuffer();
- if (paramsMap == null) {
- return param.toString();
- }
- for (Iterator<Map.Entry<String, String>> it = paramsMap.entrySet().iterator(); it.hasNext();) {
- Map.Entry<String, String> e = it.next();
- param.append("&").append(e.getKey()).append("=").append(e.getValue());
- }
- return param.toString().substring(1);
- }
- /**
- * @Description: 关闭IO
- * @param in
- * @param uc
- * @param inStream
- * @param outStream
- * @return void
- * @throws
- * @author: syuf
- * @date: 2017年11月20日 下午5:15:35
- */
- private static void close(BufferedReader in, HttpsURLConnection uc, InputStream inStream, OutputStream outStream) {
- try {
- if (in != null) {
- in.close();
- }
- if (uc != null) {
- uc.disconnect();
- }
- if (inStream != null) {
- inStream.close();
- }
- if (outStream != null) {
- outStream.close();
- }
- } catch (IOException e) {
- LOG.error("[HttpsClient]关闭流异常", e);
- }
- }
- }
HttpClient详解的更多相关文章
- android 的android httpClient详解
AndroidHttpClient结构: public final class AndroidHttpClient extends Object implements HttpClient 前言: 这 ...
- HttpClient 详解一《C#高级编程(第9版)》
1.异步调用 Web 服务 static void Main(string[] args) { Console.WriteLine("In main before call to GetDa ...
- JDK httpClient 详解(源码级分析)——概览及架构篇
1. 前言 2018年9月,伴随着java 11的发布,内置的httpclient正式登上了历史的舞台.此前,JDK内置的http工具URLConnection性能羸弱,操作繁琐,饱受诟病,也因此令如 ...
- HttpClient详解,Java发送Http的post、get方式请求 --待整理
http://www.cnblogs.com/loveyakamoz/archive/2011/07/21/2112804.html http://blog.csdn.net/wangpeng047/ ...
- HttpClient使用详解(转)
HttpClient使用详解 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们再讨论),它不仅是客户 ...
- HttpClient使用详解
http://itindex.net/detail/52566-httpclient HttpClient使用详解 标签: httpclient | 发表时间:2015-01-22 12:07 | 作 ...
- Java进阶(三十二) HttpClient使用详解
Java进阶(三十二) HttpClient使用详解 Http协议的重要性相信不用我多说了,HttpClient相比传统JDK自带的URLConnection,增加了易用性和灵活性(具体区别,日后我们 ...
- 调用链系列一、Zipkin架构介绍、Springboot集承(springmvc,HttpClient)调用链跟踪、Zipkin UI详解
1.Zipkin是什么 Zipkin分布式跟踪系统:它可以帮助收集时间数据,解决在microservice架构下的延迟问题:它管理这些数据的收集和查找:Zipkin的设计是基于谷歌的Google Da ...
- gvoory脚本中关于HttpClient使用详解实例
一.gvoory脚本中关于HttpClient使用详解实例 HttpClient:是一个接口 首先需要先创建一个DefaultHttpClient的实例 HttpClient httpClient=n ...
随机推荐
- Linux 进程、线程运行在指定CPU核上
/******************************************************************************** * Linux 进程.线程运行在指定 ...
- 使用IAR编译STM8S 怎样生产烧录文件
IAR编译后能够生成的烧录文件格式有4中,例如以下 第一种是Motorola,其生成文件和STVD生成烧录文件.s19格式一样的,即能够通用 另外一种是16进制,keil等等常都用到的. 第三种是 ...
- python random模块(随机数)详解
使用前要先导入random模块 import random random.randomrandom.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 random ...
- 5.Appium+真机Demo
1.连接真机后,执行代码时出现错误:A new session could not be created. (Original error: Could not extract PIDs from p ...
- git hooks 的学习使用
示例网址: https://my.oschina.net/u/3477605/blog/1806238 https://www.jianshu.com/p/935409ce4c9a https://w ...
- 字符串作为freemarker模板的简单实现例子
本文转载自:http://blog.csdn.net/5iasp/article/details/27181365 package com.test.demo; import java.io.IOEx ...
- SlickEdit V21 2016 破解教程,win linux mac
最近主要工作系统转到LInux上面来了,Slickedit的安装破解也费了些事,今天将过程整理一下做个记录. 说明:SlickEdit pro V21.03 Linux 64位实测可用,MAC实测可用 ...
- 马士兵Spring-AOP-Aspect例子使用(1)
一.例子1: 1.工程结构: 2. User.java: package com.cy.model; public class User { private String username; priv ...
- 匹配ip等的正则式
- 温故而知新-面向对象的PHP
1 类的多态 不同的类对同一操作可以有不同的行为. 比如自行车和汽车都有移动这个成员函数行为, 那么自行车类可以移动,行为和汽车的移动行为肯定不同. 2 析构函数不能有参数 3 __set和__get ...