Rest Get: 如何在URL的查询参数中添加“带有查询参数的URL”?

huangapple 未分类评论49阅读模式
英文:

Rest Get: How to add "URL with Query Parameters" in Query Parameters of a URL?

问题

我有以下的要求:

 /paymenturl?ordernr=123&amount=234&ourOwnCallbackUrl=$api/receipt?contractid=3232&callbackurl=https://somthing.com&fallbackurl=https:something.com&notification=hit-hard
  1. 是否可以将网址添加到查询参数中? (callbackUrl)
  2. 是否可以将步骤1添加到查询参数的值中? (ourOwnCallbackUrl)
  3. 是否可以将步骤1添加到步骤2中以形成主网址? (/paymenturl)

问题基本上是如何将另一个网址添加到查询参数中,以及是否可以进一步嵌套?

英文:

I have got requirements like below:

Rest Get: 如何在URL的查询参数中添加“带有查询参数的URL”?

 /paymenturl?ordernr=123&amount=234&ourOwnCallbackUrl=$api/receipt?contractid=3232&callbackurl=https://somthing.com&fallbackurl=https:something.com&notification=hit-hard
  1. Is it possible to add url in query parameter? (callbackUrl)
  2. Is it possible to add Step 1 into value of Query Parameter? (ourOwnCallbackUrl)
  3. Is it possible to add Step1 in Step 2 to main url? (/paymenturl)

The question is basically how to add another URL to query parameter and can it be nested further?

答案1

得分: 0

你必须转义特殊字符(如 &)。我看到两种常见的方法:

  • 使用百分比编码进行编码

    %20%2Fpaymenturl%3Fordernr%3D123%26amount%3D234%26ourOwnCallbackUrl%3D%24api%2Freceipt%3Fcontractid%3D3232%26callbackurl%3Dhttps%3A%2F%2Fsomthing.com%26fallbackurl%3Dhttps%3Asomething.com%26notification%3Dhit-hard

  • 或者您可以创建一个完整的数据传输对象(DTO),并使用请求正文与控制器之间进行发送/接收。

英文:

you have to escape the special characters (like &) I see two common ways:

  • encode it in percent-encoded

    %20%2Fpaymenturl%3Fordernr%3D123%26amount%3D234%26ourOwnCallbackUrl%3D%24api%2Freceipt%3Fcontractid%3D3232%26callbackurl%3Dhttps%3A%2F%2Fsomthing.com%26fallbackurl%3Dhttps%3Asomething.com%26notification%3Dhit-hard

  • or you can create a complete DTO (Data transfer object ) and use the request body to send/receive it from your controller.

huangapple
  • 本文由 发表于 2020年6月6日 01:05:48
  • 转载请务必保留本文链接:https://java.coder-hub.com/62220635-2.html
匿名

发表评论

匿名网友

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

确定