gpt4 book ai didi

java - ReSTLet 无法处理 json

转载 作者:行者123 更新时间:2023-12-02 05:31:32 26 4
gpt4 key购买 nike

这是我的简单 ReSTLet 代码:

public class MailServerResource extends ServerResource {

@Get("json")
public String getMail() {
return this.getRequest().getEntityAsText();
}

@Post("json")
public String sendMail() {
return this.getRequest().getEntityAsText();
}
}

现在,当我访问此资源并传递此字符串时:

{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}

它抛出:

The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method

enter image description here

最佳答案

你能尝试一下这个语法吗?

@Post("json")
public String sendMail(String json) {
return json;
}

带注释的方法可以包含表示请求实体(如果有)的单个参数。

注意:顺便说一下,Get 请求没有有效负载。该指令没有任何意义:

this.getRequest().getEntityAsText()

关于java - ReSTLet 无法处理 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25479875/

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