binarywang/WxJava · error · WxErrorException

上传失败,服务器响应空 url:%s param:%s

Error message

上传失败,服务器响应空 url:%s param:%s

What it means

The Apache HttpComponents (5.x) upload executor throws when the server returns an empty response body after a multipart POST. Identical semantics to the 4.x Apache variant (error 28): no parseable body means a fast-fail with URL and param. This is the 5.x-flavoured implementation.

Source

Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/executor/CommonUploadRequestExecutorHttpComponentsImpl.java:61

      InnerStreamBody part = new InnerStreamBody(data.getInputStream(), ContentType.DEFAULT_BINARY, data.getFileName(), data.getLength());
      MultipartEntityBuilder entityBuilder = MultipartEntityBuilder
        .create()
        .addPart(param.getName(), part)
        .setMode(HttpMultipartMode.EXTENDED);

      // 添加额外的表单字段
      if (param.getFormFields() != null && !param.getFormFields().isEmpty()) {
        for (java.util.Map.Entry<String, String> entry : param.getFormFields().entrySet()) {
          entityBuilder.addTextBody(entry.getKey(), entry.getValue(), ContentType.TEXT_PLAIN.withCharset("UTF-8"));
        }
      }

      HttpEntity entity = entityBuilder.build();
      httpPost.setEntity(entity);
    }
    String responseContent = requestHttp.getRequestHttpClient().execute(httpPost, Utf8ResponseHandler.INSTANCE);
    if (StringUtils.isEmpty(responseContent)) {
      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;
  }

  /**
   * 内部流 请求体
   */
  @Getter
  public static class InnerStreamBody extends InputStreamBody {

    private final long contentLength;

    public InnerStreamBody(final InputStream in, final ContentType contentType, final String filename, long contentLength) {
      super(in, contentType, filename);

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Retry the upload — empty bodies are frequently transient.
  2. Check apiHostUrl/proxy configuration and body-size limits.
  3. Log the HTTP status and headers (not the body, which is empty) to localise the layer dropping the response.
  4. Confirm payload size is within endpoint limits.

Example fix

// before
String r = service.upload(param);

// after — guard + retry
try {
  return service.upload(param);
} catch (WxErrorException e) {
  if (e.getMessage() != null && e.getMessage().contains("服务器响应空")) {
    Thread.sleep(1000);
    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

When it happens

Trigger: WeChat or a configured proxy returns HTTP 200 with an empty body to the HttpComponents 5.x client during an upload; gateway/WAF stripping; silent upstream body-size enforcement.

Common situations: Using HTTP_COMPONENTS backend and hitting an infra layer that returns empty; large-file uploads exceeding a proxy limit; transient connection resets.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/7cd4bdcf8a8421fd. Report an issue: GitHub.