我正在用 Java 编程。 我开发了一个测试 Web 服务,在其中传递随机 json,该服务向我返回 hello
这里是网络服务代码:
@Path("test")
@GET
@Consumes(MediaType.APPLICATION_JSON)
public String test(@HeaderParam("token") String token, @QueryParam("array")String array)
{
return "hello";
}
我用curl调用服务
curl -v -H 'token:aaaa' 'http://140.145.1.2/clayapi/restservices/test?array=[{"name":"george","lastname":"ronney"}]';
错误消息:
curl: (3) [globbing] illegal character in range specification at pos 60
我尝试添加 -g 但不起作用..我该怎么办?
最佳答案
使用 -G
以及 --data-urlencode
:
curl -v -G 'http://example.org' \
-H 'header:value' \
--data-urlencode 'array=[{"name":"george","lastname":"ronney"}]'
来自documentation :
-G
,--get
When used, this option will make all data specified with
-d
,--data
,--data-binary
or--data-urlencode
to be used in an HTTPGET
request instead of thePOST
request that otherwise would be used. The data will be appended to the URL with a?
separator. [...]
--data-urlencode <data>
(HTTP) This posts data, similar to the other
-d
,--data
options with the exception that this performs URL-encoding. [...]
关于java - 我如何使用带有 json 参数的curl 调用Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55166413/