ASP.NET的查询字符串编码和解码 [英] asp .net query string encoding and decoding

查看:141
本文介绍了ASP.NET的查询字符串编码和解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我键入以下URL到我的网页浏览器和preSS进入。

I type the following url into my web browser and press enter.

http://localhost/website.aspx?paymentID=6++7d6CZRKY%3D&language=English

现在在我的code,当我做HttpContext.Current.Request.QueryString [paymentID]

Now in my code when I do HttpContext.Current.Request.QueryString["paymentID"],

我得到6 7d6CZRKY =

I get 6 7d6CZRKY=

但是当我做HttpContext.Current.Request.QueryString.ToString()我看到以下内容:

but when I do HttpContext.Current.Request.QueryString.ToString() I see the following:

paymentID = 6 + 7d6CZRKY%3D&安培;语言=英语

paymentID=6++7d6CZRKY%3D&language=English

我想提取用户在Web浏览器中键入URL实际支付ID的事情。我不担心,因为该URL是否连接codeD或没有。因为我知道有一个奇怪的事情会在这里%3D和+在同一时间标志!但我确实需要实际的+号。不知怎的,它会去coded到空间,当我做HttpContext.Current.Request.QueryString [paymentID。

The thing I want to extract the actual payment id that the user typed in the web browser URL. I am not worried as to whether the url is encoded or not. Because I know there is a weird thing going on here %3D and + sign at the same time ! But I do need the actual + sign. Somehow it gets decoded to space when I do HttpContext.Current.Request.QueryString["paymentID"].

我只是想提取用户键入的实际支付ID。什么是做到这一点的最好方法是什么?

I just want to extract the actual payment ID that the user typed. What's the best way to do it?

感谢您。

推荐答案

您需要连接code中的URL第一,使用URLEn code()。 + 在网址等于一个空间,所以必须是EN coded到%2B。

You'll need to encode the URL first, using URLEncode(). + in URL equals a space so needs to be encoded to %2b.

string paymentId = Server.UrlEncode("6++7d6CZRKY=");
// paymentId = 6%2b%2b7d6CZRKY%3d

现在

string result = Request.QueryString["paymentId"].ToString();
//result = 6++7d6CZRKY=

然而

string paymentId = Server.UrlEncode("6  7d6CZRKY=");
//paymentId looks like you want it, but the + is a space -- 6++7d6CZRKY%3d

string result = Request.QueryString["paymentId"].ToString();
//result = 6 7d6CZRKY=

这篇关于ASP.NET的查询字符串编码和解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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