400:[无主体] - 向服务器发送发布请求时的不良请求
我已经生成(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我设法找到了原因。这是由于我有效载荷中一个成员的基类缺少财产而发生的。
这是详细信息
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