Skip to content

Commit 59fc913

Browse files
author
ecoolper
committed
okhttp使用方式有错误,body().toString()修改为body().string()
1 parent 6b7c86d commit 59fc913

File tree

12 files changed

+17
-12
lines changed

12 files changed

+17
-12
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public Request authenticate(Route route, Response response) throws IOException {
213213
String contentType = response.header("Content-Type");
214214
if (contentType != null && contentType.startsWith("application/json")) {
215215
// application/json; encoding=utf-8 下载媒体文件出错
216-
throw new WxErrorException(WxError.fromJson(response.body().toString()));
216+
throw new WxErrorException(WxError.fromJson(response.body().string()));
217217
}
218218

219219
String fileName = getFileName(response);

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public Request authenticate(Route route, Response response) throws IOException {
136136
Request request = new Request.Builder().url(uri).post(body).build();
137137

138138
Response response = client.newCall(request).execute();
139-
String responseContent = response.body().toString();
139+
String responseContent = response.body().string();
140140
WxError error = WxError.fromJson(responseContent);
141141
if (error.getErrorCode() != 0) {
142142
throw new WxErrorException(error);

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public Request authenticate(Route route, Response response) throws IOException {
141141
Request request = new Request.Builder().url(uri).build();
142142

143143
Response response = client.newCall(request).execute();
144-
String responseContent = response.body().toString();
144+
String responseContent = response.body().string();
145145
WxError error = WxError.fromJson(responseContent);
146146
if (error.getErrorCode() != 0) {
147147
throw new WxErrorException(error);

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public Request authenticate(Route route, Response response) throws IOException {
156156
Request request = new Request.Builder().url(uri).post(body).build();
157157

158158
Response response = client.newCall(request).execute();
159-
String responseContent = response.body().toString();
159+
String responseContent = response.body().string();
160160
WxError error = WxError.fromJson(responseContent);
161161
if (error.getErrorCode() != 0) {
162162
throw new WxErrorException(error);

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/okhttp/WxCpServiceImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public Request authenticate(Route route, Response response) throws IOException {
6868
} catch (IOException e) {
6969
e.printStackTrace();
7070
}
71-
String resultContent = response.body().toString();
71+
String resultContent = null;
72+
try {
73+
resultContent = response.body().string();
74+
} catch (IOException e) {
75+
e.printStackTrace();
76+
}
7277
WxError error = WxError.fromJson(resultContent);
7378
if (error.getErrorCode() != 0) {
7479
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/okhttp/WxMpServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Request authenticate(Route route, Response response) throws IOException {
6666

6767
Request request = new Request.Builder().url(url).get().build();
6868
Response response = client.newCall(request).execute();
69-
String resultContent = response.body().toString();
69+
String resultContent = response.body().string();
7070
WxError error = WxError.fromJson(resultContent);
7171
if (error.getErrorCode() != 0) {
7272
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialDeleteRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Request authenticate(Route route, Response response) throws IOException {
102102
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
103103
Request request = new Request.Builder().url(uri).post(requestBody).build();
104104
Response response = client.newCall(request).execute();
105-
String responseContent = response.body().toString();
105+
String responseContent = response.body().string();
106106
WxError error = WxError.fromJson(responseContent);
107107
if (error.getErrorCode() != 0) {
108108
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialNewsInfoRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Request authenticate(Route route, Response response) throws IOException {
104104
Request request = new Request.Builder().url(uri).post(requestBody).build();
105105

106106
Response response = client.newCall(request).execute();
107-
String responseContent = response.body().toString();
107+
String responseContent = response.body().string();
108108

109109
WxError error = WxError.fromJson(responseContent);
110110
if (error.getErrorCode() != 0) {

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Request authenticate(Route route, Response response) throws IOException {
104104
RequestBody body =bodyBuilder.build();
105105
Request request = new Request.Builder().url(uri).post(body).build();
106106
Response response = client.newCall(request).execute();
107-
String responseContent = response.body().toString();
107+
String responseContent = response.body().string();
108108
WxError error = WxError.fromJson(responseContent);
109109
if (error.getErrorCode() != 0) {
110110
throw new WxErrorException(error);

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialVideoInfoRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Request authenticate(Route route, Response response) throws IOException {
7777
RequestBody requestBody =new FormBody.Builder().add("media_id", materialId).build();
7878
Request request = new Request.Builder().url(uri).post(requestBody).build();
7979
Response response = client.newCall(request).execute();
80-
String responseContent = response.body().toString();
80+
String responseContent = response.body().string();
8181
WxError error = WxError.fromJson(responseContent);
8282
if (error.getErrorCode() != 0) {
8383
throw new WxErrorException(error);

0 commit comments

Comments
 (0)