gpt4 book ai didi

java - 通过 POST 获取 204 响应代码,其中包含 json 实体

转载 作者:行者123 更新时间:2023-12-01 12:27:09 25 4
gpt4 key购买 nike

不确定如何使此代码返回 200 响应。请求/响应中似乎有“无内容”/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 是响应的有效选择,请参阅 RFC 7231 Section-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. Metadata in the response header fields refer to the target resource and its selected representation after the requested action was applied [...].

通常,访问客户端(您)希望或需要某种响应,例如接收发布内容的远程 ID,以便之后能够访问资源(例如使用 GET ./foo/{ID}/bar)。因此,应包含响应 header 字段中的元数据...在您的响应中查看该元数据

Afaig,您无法操纵您的请求来获取 200 OK - 除了,服务器提供一些“特殊”功能。

祝你有美好的一天...

关于java - 通过 POST 获取 204 响应代码,其中包含 json 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26241056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com