Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode a url encoding string on Windows Mobile?

I have received an url encoding string from the server, e.g http%3a%2f%2fstatic.csbew.com%2f%2fcreative%2fpd_test_pptv%2f320x60.png

I want to decode it to normal url string. I find this method, but this doesn't work on compact framework.

string url = System.Web.HttpUtility.UrlDecode(strURL, Encoding.GetEncoding("GB2312"));

Any idea about how to decode the string?

like image 834
Chilly Zhong Avatar asked Jul 12 '10 09:07

Chilly Zhong


People also ask

How do you check string is URL encoded or not?

So you can test if the string contains a colon, if not, urldecode it, and if that string contains a colon, the original string was url encoded, if not, check if the strings are different and if so, urldecode again and if not, it is not a valid URI.

What is the best way to URL encode a string?

In JavaScript, PHP, and ASP there are functions that can be used to URL encode a string. PHP has the rawurlencode() function, and ASP has the Server. URLEncode() function. In JavaScript you can use the encodeURIComponent() function.

What is addingPercentEncoding?

addingPercentEncoding(withAllowedCharacters:)Returns a new string made from the receiver by replacing all characters not in the specified set with percent-encoded characters.

Does browser automatically decode URL?

It is a usual task in web development, and this is generally done while making a GET request to the API with the query params. The query params must also be encoded in the URL string, where the server will decode this. Many browsers automatically encode and decode the URL and the response string.


1 Answers

Maybe this will help you:

 /// <summary>
    /// UrlDecodes a string without requiring System.Web
    /// </summary>
    /// <param name="text">String to decode.</param>
    /// <returns>decoded string</returns>
    public static string UrlDecode(string text)
    {
        // pre-process for + sign space formatting since System.Uri doesn't handle it
        // plus literals are encoded as %2b normally so this should be safe
        text = text.Replace("+", " ");
        return System.Uri.UnescapeDataString(text);
    }

    /// <summary>
    /// UrlEncodes a string without the requirement for System.Web
    /// </summary>
    /// <param name="String"></param>
    /// <returns></returns>
    public static string UrlEncode(string text)
    {
        // Sytem.Uri provides reliable parsing
        return System.Uri.EscapeDataString(text);
    }

Originally found here: geekstoolbox

like image 163
Aykut Çevik Avatar answered Oct 07 '22 15:10

Aykut Çevik