gpt4 book ai didi

java - List 作为 GET 方法的输入

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

我有 REST 服务。 GET方法的输入类型为List<String> :

@GET
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<myObject> getData(List<String> IDs) {
....
}

我尝试使用curl来测试这个方法。我使用了很多不同的数据组合:

curl -X GET --data-binary '{"IDs":["TestString1","TestString2"]}' -H "Content-Type: application/json" http://localhost:8080/myModule/rs/getData -v
'{"TestString1","TestString2"}'
'["TestString1","TestString2"]'
so on

但我总是得到回应:

Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
or
Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

是否可以输入List<String> ?我的curl请求不正确吗?

最佳答案

看起来您是sending a POST request :

--data-binary < data>

(HTTP) This posts data exactly as specified with no extra processing whatsoever.

-X sets a custom request type ,我猜它没有检测到需要对数据进行 URL 编码:

-X, --request < command>

(HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.

所以尝试使用 -G相反:

-G, --get

When used, this option will make all data specified with -d, --data or --data-binary to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator.

关于java - List<String> 作为 GET 方法的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573874/

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