diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java b/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java index 5cdec5e..dfcdf1a 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java @@ -154,14 +154,16 @@ public class ClientHttpRequest extends HttpEntityEnclosingRequestBase impleme if (null == request){ return this; } - if (request instanceof Map) { + if (request instanceof HttpEntity){ + setEntity((HttpEntity)request); + } else if (request instanceof Map) { StringEntity entity = new StringEntity(getMapToParameters((Map) request), APPLICATION_FORM_URLENCODED_UTF_8); setEntity(entity); } else if (request instanceof String) { StringEntity entity = new StringEntity((String) request, APPLICATION_FORM_URLENCODED_UTF_8); setEntity(entity); } else { - StringEntity entity = new StringEntity(JSON.toJSONString(request), APPLICATION_FORM_URLENCODED_UTF_8); + StringEntity entity = new StringEntity(JSON.toJSONString(request), ContentType.APPLICATION_JSON); setEntity(entity); } diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/http/HttpStringEntity.java b/pay-java-common/src/main/java/com/egzosn/pay/common/http/HttpStringEntity.java new file mode 100644 index 0000000..56fed0e --- /dev/null +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/http/HttpStringEntity.java @@ -0,0 +1,55 @@ +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 + * @email egzosn@gmail.com + * @date 2017/12/20 + */ +public class HttpStringEntity extends StringEntity { + + public HttpStringEntity(Map request, ContentType contentType) throws UnsupportedCharsetException { + super(getMapToParameters(request), contentType); + } + + public HttpStringEntity(Map request, String charset) throws UnsupportedCharsetException { + super(getMapToParameters(request), charset); + } + + public HttpStringEntity(Map request, Charset charset) { + super(getMapToParameters(request), charset); + } + + public HttpStringEntity(Map 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); + } + + +}