@@ -39,12 +39,13 @@ public class Utils {
39
39
40
40
//传入参数特定类型
41
41
public static final String ENTITY_STRING ="$ENTITY_STRING$" ;
42
+ public static final String ENTITY_JSON ="$ENTITY_JSON$" ;
42
43
public static final String ENTITY_FILE ="$ENTITY_FILEE$" ;
43
44
public static final String ENTITY_BYTES ="$ENTITY_BYTES$" ;
44
45
public static final String ENTITY_INPUTSTREAM ="$ENTITY_INPUTSTREAM$" ;
45
46
public static final String ENTITY_SERIALIZABLE ="$ENTITY_SERIALIZABLE$" ;
46
47
public static final String ENTITY_MULTIPART ="$ENTITY_MULTIPART$" ;
47
- private static final List <String > SPECIAL_ENTITIY = Arrays .asList (ENTITY_STRING , ENTITY_BYTES , ENTITY_FILE , ENTITY_INPUTSTREAM , ENTITY_SERIALIZABLE , ENTITY_MULTIPART );
48
+ private static final List <String > SPECIAL_ENTITIY = Arrays .asList (ENTITY_STRING , ENTITY_JSON , ENTITY_BYTES , ENTITY_FILE , ENTITY_INPUTSTREAM , ENTITY_SERIALIZABLE , ENTITY_MULTIPART );
48
49
49
50
/**
50
51
* 是否开启debug,
@@ -92,6 +93,14 @@ public static HttpEntity map2HttpEntity(List<NameValuePair> nvps, Map<String, Ob
92
93
if (ENTITY_STRING .equals (entry .getKey ())){//string
93
94
entity = new StringEntity (String .valueOf (entry .getValue ()), encoding );
94
95
break ;
96
+ }else if (ENTITY_JSON .equals (entry .getKey ())){//json
97
+ entity = new StringEntity (String .valueOf (entry .getValue ()), encoding );
98
+ String contentType = "application/json" ;
99
+ if (encoding != null ) {
100
+ contentType += ";charset=" + encoding ;
101
+ }
102
+ ((StringEntity ) entity ).setContentType (contentType );
103
+ break ;
95
104
}else if (ENTITY_BYTES .equals (entry .getKey ())){//file
96
105
entity = new ByteArrayEntity ((byte [])entry .getValue ());
97
106
break ;
0 commit comments