如何防止双正斜杠被编码? [英] How to Prevent Double Forward Slash From Being Encoded?

查看:45
本文介绍了如何防止双正斜杠被编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向类似于以下内容的内容发出 get 请求:https://endpoint.com/path/to/what//want?参数=值

I'm making a get request to something similar to the following: https://endpoint.com/path/to/what//want?param=value

我故意在什么"和想要"之间遗漏了一个值,以测试它是否给出了 404 错误.问题是,由于某种原因,它事先被编码,发送的内容是:https://endpoint.com/path/to/what%2f%2fwant?param=value

I'm intentionally missing a value in between 'what' and 'want' to test that it gives a 404 error. The problem is that for some reason it gets encoded before hand and what is being sent through is: https://endpoint.com/path/to/what%2f%2fwant?param=value

这会导致返回 400,因为这只是一个错误的请求.

Which causes a 400 to be returned because this is just a bad request.

我知道我可以关闭编码,但有时需要对参数/值组合进行编码,所以我想避免这样做.

I know I can turn encoding off but sometimes the param/value combination will need to be encoded so I would like to avoid doing that.

我尝试使用普通连接和 StringBuilder 来形成连接字符串,但这没有任何区别.

I've tried forming the connection string using plain concatenation and StringBuilder but that made no difference.

任何提示或其他尝试尝试的事情将不胜感激.

Any tips or others things to attempt to try would be appreciated.

推荐答案

您唯一的选择是使用以下方法禁用 URL 编码:

Your only option is to disable URL encoding using:

given().urlEncoding(false). ..

然后对您希望手动进行 url 编码的部分进行 URL 编码.REST Assured 不能总是猜对,这就是这种情况.

and then URL encode the parts you wish to url encode manually. REST Assured can't always guess correctly and this is such as case.

这篇关于如何防止双正斜杠被编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆