binarywang/WxJava · error · WxErrorException
上传失败,服务器响应空 url:%s param:%s
Error message
上传失败,服务器响应空 url:%s param:%s
What it means
The OkHttp upload executor throws when response.body() is null or responseBody.string() is empty after the multipart POST. Same fast-fail semantics as the other three upload executors: an empty body cannot be parsed into a WxError. OkHttp distinguishes a null body from an empty string body and treats both as failure here.
Source
Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/executor/CommonUploadRequestExecutorOkHttpImpl.java:52
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder()
.setType(MediaType.get("multipart/form-data"))
.addFormDataPart(param.getName(), param.getData().getFileName(), requestBody);
// 添加额外的表单字段
if (param.getFormFields() != null && !param.getFormFields().isEmpty()) {
for (java.util.Map.Entry<String, String> entry : param.getFormFields().entrySet()) {
bodyBuilder.addFormDataPart(entry.getKey(), entry.getValue());
}
}
RequestBody body = bodyBuilder.build();
Request request = new Request.Builder().url(uri).post(body).build();
try (Response response = requestHttp.getRequestHttpClient().newCall(request).execute()) {
ResponseBody responseBody = response.body();
String responseContent = responseBody == null ? "" : responseBody.string();
if (responseContent.isEmpty()) {
throw new WxErrorException(String.format("上传失败,服务器响应空 url:%s param:%s", uri, param));
}
WxError error = WxError.fromJson(responseContent, wxType);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
return responseContent;
}
}
/**
* 通用上传输入 到 OkHttp 请求提 适配器
*/
@AllArgsConstructor
public static class CommonUpdateDataToRequestBodyAdapter extends RequestBody {
private static final MediaType CONTENT_TYPE = MediaType.get("application/octet-stream");
private CommonUploadData data;View on GitHub (pinned to 1c43293a3c)
Solutions
- Retry the upload — null/empty bodies are frequently transient.
- Check apiHostUrl/proxy and body-size limits.
- Verify the endpoint path and that WeChat expects this upload verb/content-type.
- Log response.code() and headers to localise the empty-body source.
Example fix
// before
String r = service.upload(param);
// after
try {
return service.upload(param);
} catch (WxErrorException e) {
if (e.getMessage() != null && e.getMessage().contains("服务器响应空")) {
return service.upload(param);
}
throw e;
} Defensive patterns
Strategy: retry
Try / catch
int attempts = 0;
while (true) {
try {
return service.upload(param);
} catch (WxErrorException e) {
boolean empty = e.getMessage() != null && e.getMessage().contains("服务器响应空");
if (!empty || ++attempts > 2) throw e;
Thread.sleep(1000L * attempts);
}
} Prevention
- Verify the OkHttp client's proxy/apiHostUrl configuration.
- Confirm upload size is within endpoint limits.
- Log response.code() and headers when this fires to localise the empty/null body.
When it happens
Trigger: OkHttp receives a 204 or a 200 with a null/empty body during upload; gateway/WAF strips the response; the connection is closed before any body bytes.
Common situations: OkHttp backend behind a stripping proxy; large upload silently rejected by an intermediary; transient reset; wrong endpoint returning empty.
Related errors
- 上传失败,服务器响应空 url:%s param:%s
- 上传失败,服务器响应空 url:%s param:%s
- 上传失败,服务器响应空 url:%s param:%s
- 微信服务端异常,超出重试次数!
- 错误代码:{errorCode}, 错误信息:{errorMsg}
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/c7cb7390bd0eb821.
Report an issue: GitHub.