我注意到Stackoverflow登录/注销链接上的returnurl URL参数没有被转义,但是当我尝试将路径作为参数添加到路由时,它会被转义.
所以/ login?returnurl =/questions/ask shows/login?returnurl =%2fquestions%2fask,这有点难看.如何让它不能逃避returnurl值?
这是我在代码中所做的事情:
Html.ActionLink("Login", "Login", "Account", new { returnurl=Request.Path }, null)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Qt 4编码URL.看起来在Qt 3中,方法是QUrl::encode,但显然QUrl是从Qt 3重写为Qt 4.我查看了文档并没有看到任何等效的方法.有什么我想念的吗?
HttpUtility.UrlEncode("!!!test", Encoding.GetEncoding("windows-1251"))
Run Code Online (Sandbox Code Playgroud)
它不编码!来%21-为什么?
我正在尝试使用OAuth从站点获取访问令牌和密码.请求令牌和请求秘密的交换顺利,但是当到达获取访问令牌的时候,我得到了错误"Invalid signature. Expected signature base string."
有没有人见过这个错误或知道什么可能是错的?这是我要回来的数据(在urldecode它之后):
Invalid signature. Expected signature base string: POST
https://www.readability.com/api/rest/v1/oauth/access_token
oauth_consumer_key=my_consumer_key
oauth_nonce=d9aff6a0011a633253c5ff9613c6833d79d52cbe
oauth_signature_method=HMAC-SHA1
oauth_timestamp=1311186899
oauth_token=C8GF7D6ytPzQKdZVpy
oauth_verifier=ncUV4tJSrS
oauth_version=1.0
signature=7jUuk6fsEL8XNYxVWcsfGXEreK0%3D
Run Code Online (Sandbox Code Playgroud) 我有一个简单的ApiController
public HttpResponseMessage Put(int orderid, [FromBody] Order order)
{
// Do something useful with order.Notes here
}
Run Code Online (Sandbox Code Playgroud)
和一个类(实际的类包含更多属性)
public class Order
{
public string Notes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并希望处理以下类型的PUT请求
PUT http://localhost/api/orders/{orderid}
Content-Type: application/x-www-form-urlencoded
notes=sometext
Run Code Online (Sandbox Code Playgroud)
一切正常,但空值传递为null
notes=blah // passes blah
notes= // Passes null
someothervalue=blah // Passes null
Run Code Online (Sandbox Code Playgroud)
是否可以让ApiController区分空值和缺失值?
如何在XSLT中对url参数进行urlencode?
在php中有一个函数rawurlencode可以完成我想要的,urlencode根据RFC 3986.
http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip
urlencode($myurl);
Run Code Online (Sandbox Code Playgroud)
问题是,urlencode还将编码使URL无法使用的斜杠.我怎么能只编码最后的文件名?
我使用用户输入的URL作为文本来初始化QUrl对象.后来我想将QUrl转换回字符串以显示它并使用正则表达式进行检查.只要用户没有输入任何百分比编码的URL,这就可以正常工作.
为什么以下示例代码不起作用?
qDebug() << QUrl("http://test.com/query?q=%2B%2Be%3Axyz%2Fen").toDisplayString(QUrl::FullyDecoded);
Run Code Online (Sandbox Code Playgroud)
它根本不解码任何百分比编码的字符.它应该打印"http://test.com/query?q=++e:xyz/en"但实际打印"http://test.com/query?q=%2B%2Be%3Axyz%2Fen".
我还尝试了许多其他方法,如fromUserInput(),但我无法在Qt5.3中使代码正常工作.
有人可以解释我如何做到这一点,以及为什么上面的代码不起作用(即显示解码的URL),即使使用QUrl :: FullyDecoded?
UPDATE
获取fromPercentEncoding()提示后,我尝试了以下代码:
QUrl UrlFromUserInput(const QString& input)
{
QByteArray latin = input.toLatin1();
QByteArray utf8 = input.toUtf8();
if (latin != utf8)
{
// URL string containing unicode characters (no percent encoding expected)
return QUrl::fromUserInput(input);
}
else
{
// URL string containing ASCII characters only (assume possible %-encoding)
return QUrl::fromUserInput(QUrl::fromPercentEncoding(input.toLatin1()));
}
}
Run Code Online (Sandbox Code Playgroud)
这允许用户输入unicode URL和百分比编码的URL,并且可以解码这两种URL以进行显示/匹配.但是,百分比编码的URL在QWebView中不起作用... Web服务器响应不同(它返回了不同的页面).很明显,QUrl :: fromPercentEncoding()不是一个干净的解决方案,因为它有效地改变了URL.我可以在上面的函数中创建两个QUrl对象...一个直接构造,一个使用fromPercentEncoding()构建,第一个用于QWebView,后者仅用于显示/匹配......但这看起来很荒谬.
我有一个奇怪的问题,urlencoding加号+作为针对API的请求的查询参数.API的文档说明:
日期必须采用W3C格式,例如'2016-10-24T13:33:23 + 02:00'.
到目前为止一直很好,所以我使用这个代码(minimalized)生成url,使用Spring的UriComponentBuilder:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX");
ZonedDateTime dateTime = ZonedDateTime.now().minusDays(1);
String formated = dateTime.format(formatter);
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(baseUrl);
uriComponentsBuilder.queryParam("update", formated);
uriComponentsBuilder.build();
String url = uriComponentsBuilder.toUriString();
Run Code Online (Sandbox Code Playgroud)
未编码的查询将如下所示:
https://example.com?update=2017-01-05T12:40:44+01
Run Code Online (Sandbox Code Playgroud)
编码的字符串导致:
https://example.com?update=2017-01-05T12:40:44%2B01
Run Code Online (Sandbox Code Playgroud)
这是(恕我直言)一个正确编码的查询字符串.请参阅%2B替换查询字符串末尾的+in +01.
但是,现在,当我使用编码的url针对API发送请求时,我收到一条错误消息,指出无法处理请求.
但是,如果我在发送请求之前将其替换为%2Ba +,则可以:
url.replaceAll("%2B", "+");
Run Code Online (Sandbox Code Playgroud)
从我的理解,+标志是一个替代whitespace.因此,解码后服务器真正看到的URL必须是
https://example.com?update=2017-01-05T12:40:44 01
Run Code Online (Sandbox Code Playgroud)
我对这个假设是对的吗?
有什么我可以做的,除了联系API的所有者使其使用正确编码的查询,除了奇怪的非标准字符串替换?
更新:
根据规范RFC 3986(第3.4节),+查询参数中的符号不需要编码.
3.4.询问
查询组件包含非分层数据,与路径组件(第3.3节)中的数据一起用于标识
URI方案和命名权限
(如果有)范围内的资源.查询组件由第一个
问号("?")字符表示,并以数字符号("#")字符
或URI的末尾结束.伯纳斯 - 李等人.标准跟踪[第23页] RFC 3986 URI通用语法
2005年1月Run Code Online (Sandbox Code Playgroud)query = …
我正在尝试使用Jmeter记录我的Web客户端 - 服务器通信.配置Jmeter和浏览器以记录应用程序之后.从客户端到服务器发出post请求时,会发生以下错误.知道如何编码正在记录的URL吗?
java.net.URISyntaxException: Illegal character in query at index 238: http://localhost:8080/updateBoxCorrectionInstantly?examKey=16-17-%3ECBSE-%3ETERM%20I-%3ESA1-%3EVI-%3EScience-%3EA&studentName=AMOGH%20YOGESH%20KALE&studentRollno=3&studentND=-1&sheetName=cb8e806b32e9d670698655e0d2da10e3_img001210.jpg&box={%22$center%22:%22(66.0,%202253.0)%22,%22$conf%22:%22H%22,%22$corrected%22:true,%22$isAdminCorrected%22:true,%22$correction%22:%22-%22,%22$isDrawn%22:false,%22coords%22:[36,2214,96,2292],%22isTitle%22:false,%22pos%22:%22-%22,%22pred%22:%22-%22,%22boxTypeId%22:0,%22score%22:1}
at java.net.URI$Parser.fail(URI.java:2829)
at java.net.URI$Parser.checkChars(URI.java:3002)
at java.net.URI$Parser.parseHierarchical(URI.java:3092)
at java.net.URI$Parser.parse(URI.java:3034)
at java.net.URI.<init>(URI.java:595)
at java.net.URL.toURI(URL.java:949)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:232)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1075)
at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:212)
Run Code Online (Sandbox Code Playgroud)