<NME> HttpStringEntity.java
<BEF> package com.egzosn.pay.common.http;

import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Map;

import static com.egzosn.pay.common.http.UriVariables.getMapToParameters;

/**
 * 请求实体
 *
 * @author egan
 * <pre>
 * email egzosn@gmail.com
 * date 2017/12/20
 * </pre>
 */
public class HttpStringEntity extends StringEntity {

    public HttpStringEntity(Map<String, Object> request, ContentType contentType) throws UnsupportedCharsetException {
        super(getMapToParameters(request), contentType);
    }

    public HttpStringEntity(Map<String, Object> request, String charset) throws UnsupportedCharsetException {
        super(getMapToParameters(request), charset);
    }

    public HttpStringEntity(Map<String, Object> request, Charset charset) {
        super(getMapToParameters(request), charset);
    }

    public HttpStringEntity(Map<String, Object> request) throws UnsupportedEncodingException {
        super(getMapToParameters(request));
    }

    public HttpStringEntity(String string, ContentType contentType) throws UnsupportedCharsetException {
        super(string, contentType);
    }

    public HttpStringEntity(String string, String charset) throws UnsupportedCharsetException {
        super(string, charset);
    }

    public HttpStringEntity(String string, Charset charset) {
        super(string, charset);
    }

    public HttpStringEntity(String string) throws UnsupportedEncodingException {
        super(string);
    }


    public List<Header> getHeaders() {
        return headers;
    }

    /**
     * 添加请求头
     *
     * @param header 请求头
     */
    public void addHeader(Header header) {
        if (null == this.headers) {
            this.headers = new ArrayList<>();
        }
        this.headers.add(header);
    }

    /**
     * 设置请求头集
     *
     * @param headers 请求头集
     */
    public void setHeaders(List<Header> headers) {
        this.headers = headers;
    }

    /**
     * 设置请求头集
     *
     * @param headers 请求头集
     */
    public void setHeaders(Map<String, String> headers) {
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            addHeader(new BasicHeader(entry.getKey(), entry.getValue()));
        }
    }

    /**
     * 设置请求头
     *
     * @param header 请求头
     * @see com.egzosn.pay.common.http.HttpHeader
     */
    public void setHeaders(HttpHeader header) {
        this.headers = header.getHeaders();
    }


}

<MSG> http请求增加请求头的实现方式
拆分网络代理与请求授权(auth)。

<DFF> @@ -1,56 +1,203 @@
 package com.egzosn.pay.common.http;
 
+import org.apache.http.Header;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.message.BasicHeader;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
-import java.util.Map;
+import java.util.*;
 
 import static com.egzosn.pay.common.http.UriVariables.getMapToParameters;
 
 /**
- * 请求实体
+ * 请求实体，包含请求头，内容类型，编码类型等
  *
  * @author egan
- * <pre>
- * email egzosn@gmail.com
- * date 2017/12/20
- * </pre>
+ *         <pre>
+*               email egzosn@gmail.com
+*               date 2017/12/20
+*           </pre>
  */
 public class HttpStringEntity extends StringEntity {
+    /**
+     * 请求头
+     */
+    private List<Header> headers;
 
-    public HttpStringEntity(Map<String, Object> request, ContentType contentType) throws UnsupportedCharsetException {
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param headers 请求头
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(Map<String, Object> request, Header... headers) throws UnsupportedEncodingException {
+        this(getMapToParameters(request), headers);
+
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param headers 请求头
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(Map<String, Object> request, Map<String, String> headers) throws UnsupportedEncodingException {
+        this(getMapToParameters(request), headers);
+
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request     请求体
+     * @param contentType 内容类型
+     */
+    public HttpStringEntity(Map<String, Object> request, ContentType contentType) {
         super(getMapToParameters(request), contentType);
     }
 
-    public HttpStringEntity(Map<String, Object> request, String charset) throws UnsupportedCharsetException {
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param charset 字符类型
+     */
+    public HttpStringEntity(Map<String, Object> request, String charset) {
         super(getMapToParameters(request), charset);
     }
 
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param charset 字符类型
+     */
     public HttpStringEntity(Map<String, Object> request, Charset charset) {
         super(getMapToParameters(request), charset);
     }
 
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
     public HttpStringEntity(Map<String, Object> request) throws UnsupportedEncodingException {
         super(getMapToParameters(request));
     }
 
-    public HttpStringEntity(String string, ContentType contentType) throws UnsupportedCharsetException {
-        super(string, contentType);
+    /**
+     * 构造器
+     *
+     * @param request     请求体
+     * @param contentType 内容类型
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(String request, ContentType contentType) throws UnsupportedCharsetException {
+        super(request, contentType);
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param charset 字符类型
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(String request, String charset) throws UnsupportedCharsetException {
+        super(request, charset);
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param charset 字符类型
+     */
+    public HttpStringEntity(String request, Charset charset) {
+        super(request, charset);
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param headers 请求头
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(String request, Header... headers) throws UnsupportedEncodingException {
+        super(request);
+        if (null == headers) {
+            this.headers = Arrays.asList(headers);
+        }
+    }
+
+    /**
+     * 构造器
+     *
+     * @param request 请求体
+     * @param headers 请求头
+     *
+     * @throws UnsupportedEncodingException 不支持默认的HTTP字符集
+     */
+    public HttpStringEntity(String request, Map<String, String> headers) throws UnsupportedEncodingException {
+        super(request);
+        this.headers = new ArrayList<>();
+        for (String key : headers.keySet()) {
+            this.headers.add(new BasicHeader(key, headers.get(key)));
+        }
+    }
+
+    /**
+     * 获取请求头集
+     *
+     * @return 请求头集
+     */
+    public List<Header> getHeaders() {
+        return headers;
     }
 
-    public HttpStringEntity(String string, String charset) throws UnsupportedCharsetException {
-        super(string, charset);
+    /**
+     * 添加请求头
+     *
+     * @param header 请求头
+     */
+    public void addHeader(Header header) {
+        if (null == this.headers) {
+            this.headers = new ArrayList<>();
+        }
+        this.headers.add(header);
     }
 
-    public HttpStringEntity(String string, Charset charset) {
-        super(string, charset);
+    /**
+     * 设置请求头集
+     *
+     * @param headers 请求头集
+     */
+    public void setHeaders(List<Header> headers) {
+        this.headers = headers;
     }
 
-    public HttpStringEntity(String string) throws UnsupportedEncodingException {
-        super(string);
+    /**
+     * 设置请求头集
+     *
+     * @param headers 请求头集
+     */
+    public void setHeaders(Map<String, String> headers) {
+        for (String key : headers.keySet()) {
+            addHeader(new BasicHeader(key, headers.get(key)));
+        }
     }
 
 

http请求增加请求头的实现方式 拆分网络代理与请求授权(auth)。