System.Web.HttpUtility.UrlEncode C# (CSharp) Method

UrlEncode() public static method

public static UrlEncode ( byte bytes ) : string
bytes byte
return string
        public static string UrlEncode(byte[] bytes)
        {
            throw null;
        }

Same methods

HttpUtility::UrlEncode ( byte bytes, int offset, int count ) : string
HttpUtility::UrlEncode ( string str ) : string
HttpUtility::UrlEncode ( string str, System e ) : string

Usage Example

Example #1
0
    /// <summary>
    /// 构造Get请求
    /// </summary>
    static HttpWebRequest _BuildGetRequest(string url, RequestParams data,
                                           Action <HttpWebRequest> action)
    {
        //如果传入了data,则先构造请求url
        if (data != null && data.Count > 0)
        {
            StringBuilder sb = new StringBuilder(url);
            if (url.IndexOf('?') < 0)
            {
                sb.Append('?');
            }
            //build request
            foreach (var entry in data)
            {
                object v = entry.Value;
                sb.Append(HttpHelper.UrlEncode(entry.Key))
                .Append('=')
                .Append(v == null ? "" : HttpHelper.UrlEncode(v.ToString()))
                .Append('&');
            }
            //change url
            url = sb.ToString(0, sb.Length - 1);             //remove last '&'
        }

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

        req.Method = "GET";
        action?.Invoke(req);
        return(req);
    }
All Usage Examples Of System.Web.HttpUtility::UrlEncode