UriComponentsBuilder和UriComponents url编码
编码 url
2023-09-14 08:57:51 时间
Spring MVC 提供了一种机制,可以构造和编码URI -- 使用UriComponentsBuilder和UriComponents。
功能相当于 urlencode()函数,对url进行编码, 但同时还支持变量替换
UriComponents uriComponents = UriComponentsBuilder.fromUriString( "http://example.com/hotels/{hotel}/bookings/{booking}").build(); URI uri = uriComponents.expand("42", "21").encode().toUri();
嗯,expand()是用于替换所有的模板变量,encode默认使用UTF8编码。
注意,UriComponents是不可变的,expand()和encode()都是返回新的实例。
你还可以这样做:
UriComponents uriComponents = UriComponentsBuilder.newInstance() .scheme("http").host("example.com").path("/hotels/{hotel}/bookings/{booking}").build() .expand("42", "21") .encode();
在Servlet环境中,使用子类ServletUriComponentsBuilder提供的静态工厂方法可以从一个Servlet request中获取有用的URI信息:
HttpServletRequest request = ... // Re-use host, scheme, port, path and query string // Replace the "accountId" query param ServletUriComponentsBuilder ucb = ServletUriComponentsBuilder.fromRequest(request) .replaceQueryParam("accountId", "{id}").build() .expand("123") .encode();
https://www.cnblogs.com/larryzeal/p/6131664.html
相关文章
- post提交的数据有哪几种编码格式?能否通过URL参数获取用户账户密码
- 「Python 编程」编码实现网络请求库中的 URL 解析器
- 「Python 编程」编码实现网络请求库中的 URL 解析器
- URL编码表,URL编码大全
- Objective-C 对 URL 进展 URLEncode 编码
- x264代码剖析(十五):核心算法之宏块编码中的变换编码
- java插入排序兼编码注意
- 网页设计DIV+CSS——第3 天:定义语言编码
- python中url解析 or url的base64编码
- Nginx、PCRE和中文URL(UTF8编码)rewrite路径重写匹配问题
- MyEclipse的编码设置(新手查看)
- 【u211】编码
- 通过在操作系统中实际操作,学习和理解 Unicode 编码相关知识
- 【计组笔记01】计算机组成原理之冯诺依曼体系结构、计算机编码、定点数的表示、原码和补码的乘除法
- shell编码常用表
- 「Python 编程」编码实现网络请求库中的 URL 解析器
- Python编程:URL网址链接中的中文编码与解码
- js:URL、URLSearchParams解析当前页面url和查询参数
- Ansi,UTF8,Unicode,ASCII编码的差别
- 004-URL编码转换函数:escape()、encodeURI()、encodeURIComponent()
- java使用Base64编码和解码的图像文件
- SSRF中的绕过手段——字节总结得比较好,如何绕过SSRF的保护机制,DNS欺骗,使用IPV6地址,十六进制编码、八进制编码、双字编码、URL编码和混合编码等
- 【C++要笑着学】编码的由来 | basic_string模板类 | string类的常用接口讲解 | 学会查文档