问号(?)在jax-rs jersey中被替换为%3F

huangapple go评论82阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2020年8月26日 04:05:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/63586328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定