mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-12 16:37:31 +08:00
请求工具增加请求实体类型 HttpStringEntity
This commit is contained in:
@@ -154,14 +154,16 @@ public class ClientHttpRequest<T> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user