mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-04 20:57:47 +08:00
okhttp使用方式有错误,body().toString()修改为body().string()
This commit is contained in:
parent
6b7c86da95
commit
59fc9134c8
@ -213,7 +213,7 @@ public class MediaDownloadRequestExecutor extends AbstractRequestExecutor<File,
|
|||||||
String contentType = response.header("Content-Type");
|
String contentType = response.header("Content-Type");
|
||||||
if (contentType != null && contentType.startsWith("application/json")) {
|
if (contentType != null && contentType.startsWith("application/json")) {
|
||||||
// application/json; encoding=utf-8 下载媒体文件出错
|
// application/json; encoding=utf-8 下载媒体文件出错
|
||||||
throw new WxErrorException(WxError.fromJson(response.body().toString()));
|
throw new WxErrorException(WxError.fromJson(response.body().string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = getFileName(response);
|
String fileName = getFileName(response);
|
||||||
|
@ -136,7 +136,7 @@ public class MediaUploadRequestExecutor extends AbstractRequestExecutor<WxMediaU
|
|||||||
Request request = new Request.Builder().url(uri).post(body).build();
|
Request request = new Request.Builder().url(uri).post(body).build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -141,7 +141,7 @@ public class SimpleGetRequestExecutor extends AbstractRequestExecutor<String, St
|
|||||||
Request request = new Request.Builder().url(uri).build();
|
Request request = new Request.Builder().url(uri).build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -156,7 +156,7 @@ public class SimplePostRequestExecutor extends AbstractRequestExecutor<String, S
|
|||||||
Request request = new Request.Builder().url(uri).post(body).build();
|
Request request = new Request.Builder().url(uri).post(body).build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -68,7 +68,12 @@ public class WxCpServiceImpl extends AbstractWxCpServiceImpl<ConnectionPool, Okh
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
String resultContent = response.body().toString();
|
String resultContent = null;
|
||||||
|
try {
|
||||||
|
resultContent = response.body().string();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
WxError error = WxError.fromJson(resultContent);
|
WxError error = WxError.fromJson(resultContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -66,7 +66,7 @@ public class WxMpServiceImpl extends AbstractWxMpServiceImpl<ConnectionPool, Okh
|
|||||||
|
|
||||||
Request request = new Request.Builder().url(url).get().build();
|
Request request = new Request.Builder().url(url).get().build();
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String resultContent = response.body().toString();
|
String resultContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(resultContent);
|
WxError error = WxError.fromJson(resultContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -102,7 +102,7 @@ public class MaterialDeleteRequestExecutor extends AbstractRequestExecutor<Boole
|
|||||||
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
|
RequestBody requestBody = new FormBody.Builder().add("media_id", materialId).build();
|
||||||
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -104,7 +104,7 @@ public class MaterialNewsInfoRequestExecutor extends AbstractRequestExecutor<WxM
|
|||||||
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
|
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
|
@ -104,7 +104,7 @@ public class MaterialUploadRequestExecutor extends AbstractRequestExecutor<WxMpM
|
|||||||
RequestBody body =bodyBuilder.build();
|
RequestBody body =bodyBuilder.build();
|
||||||
Request request = new Request.Builder().url(uri).post(body).build();
|
Request request = new Request.Builder().url(uri).post(body).build();
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -77,7 +77,7 @@ public class MaterialVideoInfoRequestExecutor extends AbstractRequestExecutor<Wx
|
|||||||
RequestBody requestBody =new FormBody.Builder().add("media_id", materialId).build();
|
RequestBody requestBody =new FormBody.Builder().add("media_id", materialId).build();
|
||||||
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
Request request = new Request.Builder().url(uri).post(requestBody).build();
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -90,7 +90,7 @@ public class MediaImgUploadRequestExecutor extends AbstractRequestExecutor<WxMed
|
|||||||
Request request = new Request.Builder().url(uri).post(body).build();
|
Request request = new Request.Builder().url(uri).post(body).build();
|
||||||
|
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
WxError error = WxError.fromJson(responseContent);
|
WxError error = WxError.fromJson(responseContent);
|
||||||
if (error.getErrorCode() != 0) {
|
if (error.getErrorCode() != 0) {
|
||||||
throw new WxErrorException(error);
|
throw new WxErrorException(error);
|
||||||
|
@ -92,7 +92,7 @@ public class QrCodeRequestExecutor extends AbstractRequestExecutor<File, WxMpQrC
|
|||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
String contentTypeHeader = response.header("Content-Type");
|
String contentTypeHeader = response.header("Content-Type");
|
||||||
if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
|
if (MimeTypes.MIME_TEXT_PLAIN.equals(contentTypeHeader)) {
|
||||||
String responseContent = response.body().toString();
|
String responseContent = response.body().string();
|
||||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||||
}
|
}
|
||||||
try (InputStream inputStream = new ByteArrayInputStream(response.body().bytes())) {
|
try (InputStream inputStream = new ByteArrayInputStream(response.body().bytes())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user