URL Encoding using C#

前端 未结 13 1950
北荒
北荒 2020-11-22 08:05

I have an application which sends a POST request to the VB forum software and logs someone in (without setting cookies or anything).

Once the user is logged in I cre

13条回答
  •  无人及你
    2020-11-22 09:02

    In addition to @Dan Herbert's answer , You we should encode just the values generally.

    Split has params parameter Split('&','='); expression firstly split by & then '=' so odd elements are all values to be encoded shown below.

    public static void EncodeQueryString(ref string queryString)
    {
        var array=queryString.Split('&','=');
        for (int i = 0; i < array.Length; i++) {
            string part=array[i];
            if(i%2==1)
            {               
                part=System.Web.HttpUtility.UrlEncode(array[i]);
                queryString=queryString.Replace(array[i],part);
            }
        }
    }
    

提交回复
热议问题