64K Limit in URL encoding

764 views
Skip to first unread message

Majoor

unread,
Nov 16, 2011, 2:19:13 PM11/16/11
to RestSharp
Hi,

In commit f67044f829c21e9455141b2c4ca8d5ff04c0e987 a change was
introduced related to encoding.
https://github.com/restsharp/RestSharp/commit/f67044f829c21e9455141b2c4ca8d5ff04c0e987#diff-0

Instead of HttpUtility.UrlEncode it is now using Uri.EscapeDataString
to avoid issues with spaces in encoding.

Problem is that Uri.EscapeDataString is limited to 64k, so if you have
parameters that you POST and go into the body then you still run into
a 64k limit that wasn’t there before.

Regards,
Majoor

Andrew Young

unread,
Nov 16, 2011, 2:38:31 PM11/16/11
to rest...@googlegroups.com
Quickest thing to do, perhaps not the best, would be to break up the data into 64k chunks, encode it, then piece them together. This would get us around the 64k limit.

Rahul Bhansali

unread,
May 20, 2013, 9:24:44 AM5/20/13
to rest...@googlegroups.com
I ran into the same issue and ended up modifying the UrlEncode extension method to look like below: 
public static string UrlEncode(this string input)
{
            int limit = 65519;

            StringBuilder sb = new StringBuilder();
            int loops = input.Length / limit;

            for (int i = 0; i <= loops; i++)
            {
                if (i < loops)
                {
                    sb.Append(Uri.EscapeDataString(input.Substring(limit * i, limit)));
                }
                else
                {
                    sb.Append(Uri.EscapeDataString(input.Substring(limit * i)));
                }
            }

            return sb.ToString();

            // return Uri.EscapeDataString(input);
Reply all
Reply to author
Forward
0 new messages