Uri.EscapeDataString() - Invalid URI: The Uri string is too long

前端 未结 6 1668
难免孤独
难免孤独 2020-12-07 00:14

I\'m using compact framework/C# on windows mobile.

In my application I am uploading data to the server by serializing objects and using a HttpWebRequest/POST request

6条回答
  •  爱一瞬间的悲伤
    2020-12-07 01:03

    Or you could simply split your string and call Uri.EscapeDataString(string) for each block, in order to avoid reimplementing the function.

    Sample Code:

            String value = "large string to encode";
            int limit = 2000;
    
            StringBuilder sb = new StringBuilder();
            int loops = value.Length / limit;
    
            for (int i = 0; i <= loops; i++)
            {
                if (i < loops)
                {
                    sb.Append(Uri.EscapeDataString(value.Substring(limit * i, limit)));
                }
                else
                {
                    sb.Append(Uri.EscapeDataString(value.Substring(limit * i)));
                }
            }
    

提交回复
热议问题