[英]REST: query param containing an url
How to process query params that will contain values that are urls? 如何处理将包含URL值的查询参数?
For example if my endpoint is /endpoint/urls/{urls}
and the query param value urls will contain a url. 例如,如果我的端点是/endpoint/urls/{urls}
,并且查询参数值url将包含一个url。 How should I tell the server that the value of {urls}
must be escaped and treated as a string instead of a real url ? 我应该如何告诉服务器,必须对{urls}
的值进行转义并将其视为字符串而不是真实的url?
As an example : 举个例子 :
/endpoint/urls/ http://www.google.com / endpoint / urls / http://www.google.com
First of all, the example provided in your question is not a query parameter . 首先,问题中提供的示例不是query参数 。 It's a path parameter . 这是一个路径参数 。
To send a URL as a query parameter, you must use a key/value pair ( key=value
) and the value must be URL encoded: 要将URL作为查询参数发送,必须使用键/值对( key=value
),并且该值必须经过URL编码:
/endpoint?url=http%3A%2F%2Fwww.google.com
To URL encode a value (path or query parameter) in Java, you can use: 要使用Java对URL编码值(路径或查询参数),可以使用:
String valueUrlEncoded = URLEncoder.encode(value, "UTF-8")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.