Commit cced7bb81e6d65a591b53c8b2e723db7da50e6cf
1 parent
5b4a61ad
Exists in
master
1.add function support json string post
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
build.gradle
@@ -54,7 +54,7 @@ uploadArchives { | @@ -54,7 +54,7 @@ uploadArchives { | ||
54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 54 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
55 | } | 55 | } |
56 | pom.project { | 56 | pom.project { |
57 | - version '1.1.3' | 57 | + version '1.1.4' |
58 | artifactId ARTIFACT_Id | 58 | artifactId ARTIFACT_Id |
59 | groupId GROUP_ID | 59 | groupId GROUP_ID |
60 | packaging TYPE | 60 | packaging TYPE |
src/main/java/com/taover/util/UtilHttpByOkHttp.java
@@ -66,6 +66,16 @@ public class UtilHttpByOkHttp { | @@ -66,6 +66,16 @@ public class UtilHttpByOkHttp { | ||
66 | return getHttpClient(url).newCall(request).execute().body().string(); | 66 | return getHttpClient(url).newCall(request).execute().body().string(); |
67 | } | 67 | } |
68 | 68 | ||
69 | + public static String sendPostJson(String url, final Map<String, String> headers, String jsonStr) throws Exception{ | ||
70 | + //请求体 | ||
71 | + RequestBody requestBody = getReqeustBodyJson(jsonStr); | ||
72 | + | ||
73 | + //http头信息拼装 | ||
74 | + Request request = getRequestBuilder(url, headers).post(requestBody).build(); | ||
75 | + | ||
76 | + return getHttpClient(url).newCall(request).execute().body().string(); | ||
77 | + } | ||
78 | + | ||
69 | public static String sendDelete(String url, final Map<String, String> headers) throws Exception { | 79 | public static String sendDelete(String url, final Map<String, String> headers) throws Exception { |
70 | //http头信息拼装 | 80 | //http头信息拼装 |
71 | Request request = getRequestBuilder(url, headers).delete().build(); | 81 | Request request = getRequestBuilder(url, headers).delete().build(); |
@@ -110,6 +120,10 @@ public class UtilHttpByOkHttp { | @@ -110,6 +120,10 @@ public class UtilHttpByOkHttp { | ||
110 | return RequestBody.create(MediaType.parse("text/plain;charse=utf-8"), content); | 120 | return RequestBody.create(MediaType.parse("text/plain;charse=utf-8"), content); |
111 | } | 121 | } |
112 | 122 | ||
123 | + private static RequestBody getReqeustBodyJson(String jsonStr){ | ||
124 | + return RequestBody.create(MediaType.parse("application/json;charse=utf-8"), jsonStr); | ||
125 | + } | ||
126 | + | ||
113 | private static Request.Builder getRequestBuilder(String url, Map<String, String> headers){ | 127 | private static Request.Builder getRequestBuilder(String url, Map<String, String> headers){ |
114 | //http头信息拼装 | 128 | //http头信息拼装 |
115 | Request.Builder requestBuilder = new Request.Builder().url(url); | 129 | Request.Builder requestBuilder = new Request.Builder().url(url); |