简体   繁体   English

通过带有JSON实体的POST获取204重新放置代码

[英]Getting 204 respose code by POSTwith json entity in it

Not sure how to make this code getting 200 response back. 不确定如何使此代码获得200响应。 It seems there is "no content"/204 in the request/response. 在请求/响应中似乎没有“内容” / 204。

private Response doPostRequestAsJSON(String url) {

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonFeature.class);
    Client client = ClientBuilder.newClient(clientConfig);

    AuthLoginElement authLoginElement = new AuthLoginElement("user1", "pass1");

    WebTarget webTarget = client.target(url);

    Response response = webTarget.request("application/json")
            .post(Entity.entity(authLoginElement, "application/json"));

    return response;
}

204 No Content is a valid choice for the response, see RFC 7231 Section-6.3.5 : 204 No Content是响应的有效选择,请参阅RFC 7231第6.3.5节

The 204 (No Content) status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. 状态码204(无内容)指示服务器已成功满足请求,并且响应有效内容正文中没有其他要发送的内容。 Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied [...]. 响应标头字段中的元数据是指目标资源及其在应用请求的操作之后的选定表示形式。

Usually the accessing client (you) wants or needs to have some kind of response, for example to receive the remote ID of the posted content, to be able to access the resource afterwards (like with GET ./foo/{ID}/bar ). 通常,访问客户端(您)希望或需要某种响应,例如接收发布内容的远程ID,以便以后能够访问资源(例如使用GET ./foo/{ID}/bar )。 Therefore metadata in the response header fields should be included ... have a look after that in your response . 因此,响应头字段中的元数据应包括在内……请仔细阅读响应中的内容

Afaig you can't manipulate your request to get a 200 OK - except, the server provides some 'special' features. Afaig您无法操纵您的请求以获取200 OK-除非服务器提供了一些“特殊”功能。

Have a nice day ... 祝你今天愉快 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM