{"record":{"id":"c7cb7390bd0eb821","repo":"binarywang/WxJava","slug":"url-s-param-s-c7cb73","errorCode":null,"errorMessage":"上传失败，服务器响应空 url:%s param:%s","messagePattern":"上传失败，服务器响应空 url:(.+?) param:(.+?)","errorType":"exception","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/executor/CommonUploadRequestExecutorOkHttpImpl.java","lineNumber":52,"sourceCode":"    MultipartBody.Builder bodyBuilder = new MultipartBody.Builder()\n      .setType(MediaType.get(\"multipart/form-data\"))\n      .addFormDataPart(param.getName(), param.getData().getFileName(), requestBody);\n\n    // 添加额外的表单字段\n    if (param.getFormFields() != null && !param.getFormFields().isEmpty()) {\n      for (java.util.Map.Entry<String, String> entry : param.getFormFields().entrySet()) {\n        bodyBuilder.addFormDataPart(entry.getKey(), entry.getValue());\n      }\n    }\n\n    RequestBody body = bodyBuilder.build();\n    Request request = new Request.Builder().url(uri).post(body).build();\n\n    try (Response response = requestHttp.getRequestHttpClient().newCall(request).execute()) {\n      ResponseBody responseBody = response.body();\n      String responseContent = responseBody == null ? \"\" : responseBody.string();\n      if (responseContent.isEmpty()) {\n        throw new WxErrorException(String.format(\"上传失败，服务器响应空 url:%s param:%s\", uri, param));\n      }\n      WxError error = WxError.fromJson(responseContent, wxType);\n      if (error.getErrorCode() != 0) {\n        throw new WxErrorException(error);\n      }\n      return responseContent;\n    }\n  }\n\n  /**\n   * 通用上传输入 到 OkHttp 请求提 适配器\n   */\n  @AllArgsConstructor\n  public static class CommonUpdateDataToRequestBodyAdapter extends RequestBody {\n\n    private static final MediaType CONTENT_TYPE = MediaType.get(\"application/octet-stream\");\n\n    private CommonUploadData data;","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/executor/CommonUploadRequestExecutorOkHttpImpl.java#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"OkHttp backend behind a stripping proxy; large upload silently rejected by an intermediary; transient reset; wrong endpoint returning empty.","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."],"exampleFix":"// before\nString r = service.upload(param);\n\n// after\ntry {\n  return service.upload(param);\n} catch (WxErrorException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"服务器响应空\")) {\n    return service.upload(param);\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"int attempts = 0;\nwhile (true) {\n  try {\n    return service.upload(param);\n  } catch (WxErrorException e) {\n    boolean empty = e.getMessage() != null && e.getMessage().contains(\"服务器响应空\");\n    if (!empty || ++attempts > 2) throw e;\n    Thread.sleep(1000L * attempts);\n  }\n}","preventionTips":["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."],"tags":["upload","okhttp","empty-response","network","transient"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}