英文:
Question mark(?) getting replaced by %3F in jax-rs jersey
问题
在调用jax-rs jersey中的API时,我必须传递一个参数。但是参数的值被转换成了一些特殊字符。
我声明了一个变量mCopy
,根据一些条件它将取值false或true。
我的URI是
URI:- https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests?copy=true
我的代码是
Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
.path("bots")
.path("pushRequests?copy="+mcopy)
.request().header("Authorization",access_token)
.post(null, Response.class);
它抛出错误
https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests%3Fcopy=false,状态=404,原因=未找到
实际上,pushRequests?copy=mCopy
被转换为 pushRequests%3Fcopy=false
如何保持 ? 符号不变?
英文:
While calling an API in jax-rs jersey I have to pass a parameter. But that is getting converted into some special character.
I have declared a variable mCopy
which will take either false or true based on some conditions.
My URI is
URI:- https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests?copy=true
My code is
Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
.path("bots")
.path("pushRequests?copy="+mcopy")
.request().header("Authorization",access_token)
.post(null, Response.class);
it throws error
https://idcs-oda-xxxxxxx.com/api/v1/bots/pushRequests%3Fcopy=false, status=404, reason=Not Found
actually pushRequests?copy=mCopy
getting converted to pushRequests%3Fcopy=false
how can I keep ? symbol as it is?
答案1
得分: 3
你没有正确使用 API。你想要进行以下操作:
Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
.path("bots")
.path("pushRequests")
.queryParam("copy", mcopy) // 这是更改的部分
.request()
.header("Authorization", access_token)
.post(null, Response.class);
英文:
You're not using the API correctly. You want to do:
Response rawres = client.target("https://idcs-oda-xxxxxxx.com")
.path("bots")
.path("pushRequests")
.queryParam("copy", mcopy) // this is the change
.request().header("Authorization",access_token)
.post(null, Response.class);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论