标签: urlencode

如何在ASP.NET MVC中保留未转义的URL参数?

我注意到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)

asp.net-mvc routes urlencode

7
推荐指数
2
解决办法
5759
查看次数

Qt4中的URL编码

我正在尝试使用Qt 4编码URL.看起来在Qt 3中,方法是QUrl::encode,但显然QUrl是从Qt 3重写为Qt 4.我查看了文档并没有看到任何等效的方法.有什么我想念的吗?

qt qt4 urlencode

7
推荐指数
1
解决办法
8102
查看次数

HttpUtility.UrlEncode不会编码!如%21

HttpUtility.UrlEncode("!!!test", Encoding.GetEncoding("windows-1251"))
Run Code Online (Sandbox Code Playgroud)

它不编码!%21-为什么?

.net c# urlencode

7
推荐指数
1
解决办法
1618
查看次数

如何解决OAuth 1.0中的"无效签名.预期签名基本字符串"

我正在尝试使用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)

php oauth urlencode

7
推荐指数
1
解决办法
1万
查看次数

ASP.NET WebAPI将urlencoded正文中的空字符串作为null传递

我有一个简单的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区分空值和缺失值?

.net asp.net web-services urlencode asp.net-web-api

7
推荐指数
1
解决办法
1484
查看次数

我如何在XSLT中进行urlencode?

如何在XSLT中对url参数进行urlencode?

在php中有一个函数rawurlencode可以完成我想要的,urlencode根据RFC 3986.

xslt urlencode

7
推荐指数
1
解决办法
7804
查看次数

PHP urlencode - 仅编码文件名,不要触摸斜杠

http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip
urlencode($myurl);
Run Code Online (Sandbox Code Playgroud)

问题是,urlencode还将编码使URL无法使用的斜杠.我怎么能只编码最后的文件名?

php url encoding encode urlencode

7
推荐指数
2
解决办法
7442
查看次数

将带有百分比编码的QUrl转换为字符串

我使用用户输入的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,后者仅用于显示/匹配......但这看起来很荒谬.

qstring qt urlencode qurl

7
推荐指数
1
解决办法
1万
查看次数

奇怪的网址编码问题

我有一个奇怪的问题,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月

  query       = …
Run Code Online (Sandbox Code Playgroud)

java urlencode

7
推荐指数
1
解决办法
2861
查看次数

Jmeter Http代理服务器抛出java.net.URISyntaxException:索引错误时查询中的非法字符

我正在尝试使用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)

java put urlencode jmeter

7
推荐指数
1
解决办法
6090
查看次数

标签 统计

urlencode ×10

.net ×2

java ×2

php ×2

qt ×2

asp.net ×1

asp.net-mvc ×1

asp.net-web-api ×1

c# ×1

encode ×1

encoding ×1

jmeter ×1

oauth ×1

put ×1

qstring ×1

qt4 ×1

qurl ×1

routes ×1

url ×1

web-services ×1

xslt ×1