System.Net.WebUtility.UrlDecode C# (CSharp) Method

UrlDecode() private method

private UrlDecode ( string encodedValue ) : string
encodedValue string
return string
        public static string UrlDecode(string encodedValue)
        {
            return UrlDecodeInternal(encodedValue, Encoding.UTF8);
        }

Usage Example

        /// <summary>
        /// Gets Gmail request Token.
        /// </summary>
        /// <param name="callback">OAuth callback Url.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>callback</b> is null reference.</exception>
        /// <exception cref="InvalidOperationException">Is raised when this method is called in invalid state.</exception>
        public void GetRequestToken(string callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (!string.IsNullOrEmpty(m_RequestToken))
            {
                throw new InvalidOperationException("Invalid state, you have already called this 'GetRequestToken' method.");
            }

            // For more info see: http://googlecodesamples.com/oauth_playground/

            string timestamp = GenerateTimeStamp();
            string nonce     = GenerateNonce();

            string url    = "https://www.google.com/accounts/OAuthGetRequestToken?scope=" + UrlEncode(m_Scope);
            string sigUrl = "https://www.google.com/accounts/OAuthGetRequestToken";

            // Build signature base.
            StringBuilder xxx = new StringBuilder();

            xxx.Append("oauth_callback=" + UrlEncode(callback));
            xxx.Append("&oauth_consumer_key=" + UrlEncode(m_ConsumerKey));
            xxx.Append("&oauth_nonce=" + UrlEncode(nonce));
            xxx.Append("&oauth_signature_method=" + UrlEncode("HMAC-SHA1"));
            xxx.Append("&oauth_timestamp=" + UrlEncode(timestamp));
            xxx.Append("&oauth_version=" + UrlEncode("1.0"));
            xxx.Append("&scope=" + UrlEncode(m_Scope));
            string signatureBase = "GET" + "&" + UrlEncode(sigUrl) + "&" + UrlEncode(xxx.ToString());

            // Calculate signature.
            string signature = ComputeHmacSha1Signature(signatureBase, m_ConsumerSecret, null);

            //Build Authorization header.
            StringBuilder authHeader = new StringBuilder();

            //authHeader.Append("Authorization: OAuth ");
            authHeader.Append("oauth_version=\"1.0\", ");
            authHeader.Append("oauth_nonce=\"" + nonce + "\", ");
            authHeader.Append("oauth_timestamp=\"" + timestamp + "\", ");
            authHeader.Append("oauth_consumer_key=\"" + m_ConsumerKey + "\", ");
            authHeader.Append("oauth_callback=\"" + UrlEncode(callback) + "\", ");
            authHeader.Append("oauth_signature_method=\"HMAC-SHA1\", ");
            authHeader.Append("oauth_signature=\"" + UrlEncode(signature) + "\"");

            // Create web request and read response.
            Helpers.SendHttpRequest(url, "GET",
                                    contentString: null,
                                    additionalHeaders: new Dictionary <String, String>()
            {
                { "Authorization", "OAuth " + authHeader.ToString() }
            },
                                    handleResponseFunc: (WebResponse response) =>
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    foreach (string parameter in HttpUtility.UrlDecode(reader.ReadToEnd()).Split('&'))
                    {
                        string[] name_value = parameter.Split('=');
                        if (string.Equals(name_value[0], "oauth_token", Helpers.GetDefaultIgnoreCaseComparison()))
                        {
                            m_RequestToken = name_value[1];
                        }
                        else if (string.Equals(name_value[0], "oauth_token_secret", Helpers.GetDefaultIgnoreCaseComparison()))
                        {
                            m_RequestTokenSecret = name_value[1];
                        }
                    }
                }
            });
        }
All Usage Examples Of System.Net.WebUtility::UrlDecode