400:[无主体] - 向服务器发送发布请求时的不良请求

发布于 2025-02-01 05:17:04 字数 1469 浏览 4 评论 0原文

我已经生成(OpenAPI)有效负载对象。

@JsonPropertyOrder({
  MyPayload.JSON_PROPERTY_MY_PROPERTY
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = ...")
public class MyPayload {
  public static final String JSON_PROPERTY_MY_PROPERTY = "my_properties";
  private Map<String, MyPropery> myProperties = null;
...
    }

当我的客户端微服务发送发布请求时,

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [no body]

如果我将纯JSON作为Postman的有效负载发送失败,则可以正常工作,来到服务器。

据我了解客户端的问题,找不到原因((((

在我的客户端的代码下方)(Spring-Web 5.3.14)

private MyClient getMyClient() {
    MyClient myClient = new MyClient();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build());

    RestTemplate restTemplate = new RestTemplate(requestFactory);
    restTemplate.setInterceptors(
        Collections.singletonList(
            (ClientHttpRequestInterceptor) new TenantAwareClientInterceptor(storage)));
    ApiClient apiClient = new ApiClient(restTemplate);
    apiClient.setBasePath("https://myMS:poty/api/v1/...");
    myClient.setApiClient(apiClient);

    return myClient;
  }

可能是因为我的有效载荷中的对象和对象之间的某些差异和未分解的对象在服务器方面

? 当我使用所有字段null创建有效载荷时 - 一切正常工作...

有效负载可能出了什么问题?

I have generated (openapi) payload object.

@JsonPropertyOrder({
  MyPayload.JSON_PROPERTY_MY_PROPERTY
})
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = ...")
public class MyPayload {
  public static final String JSON_PROPERTY_MY_PROPERTY = "my_properties";
  private Map<String, MyPropery> myProperties = null;
...
    }

When my client micro-service sending post request - it failed with

org.springframework.web.client.HttpClientErrorException$BadRequest: 400 : [no body]

However if I would send pure Json as a payload from Postman - seems working fine, coming to the server.

As far as I understand issue on client side, can't find the reason (((

Below code of my client (spring-web 5.3.14)

private MyClient getMyClient() {
    MyClient myClient = new MyClient();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build());

    RestTemplate restTemplate = new RestTemplate(requestFactory);
    restTemplate.setInterceptors(
        Collections.singletonList(
            (ClientHttpRequestInterceptor) new TenantAwareClientInterceptor(storage)));
    ApiClient apiClient = new ApiClient(restTemplate);
    apiClient.setBasePath("https://myMS:poty/api/v1/...");
    myClient.setApiClient(apiClient);

    return myClient;
  }

May it be because of some differences between objects that are in my payload and objects that unmarshalled on server side?

UPD: Seems something wrong with the payload.
When I am creating payload with all fields null - everything is working fine...

What might be wrong with payload?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2025-02-08 05:17:04

我想我设法找到了原因。这是由于我有效载荷中一个成员的基类缺少财产而发生的。

这是详细信息

I think I managed to find the reason. This happens due to missing property in the base class of one of the members within my payload.

Here are the details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文