Created
August 8, 2014 01:14
-
-
Save droyad/b0d54c08578fc8fb21b1 to your computer and use it in GitHub Desktop.
Long FormUrlEncodedContent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //IEnumerable<KeyValuePair<string, string>> serializedParameters | |
| // Do this instead of using FormUrlEncodedContent as it only supports url escaping of strings shorter than 30,000 (or 60,000) | |
| // Would use MultipartFormDataContent but Esri doesn't look like it accepts that | |
| var pars = string.Join("&", serializedParameters.Select(p => p.Key + "=" + Encode(p.Value))); | |
| var content = new ByteArrayContent(Encoding.ASCII.GetBytes(pars)); | |
| content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); | |
| var message = await client.PostAsync(url, content); | |
| return await message.Content.ReadAsStringAsync(); | |
| private static string Encode(string value) | |
| { | |
| if (value == null) | |
| return null; | |
| if (value.Length < 32000) | |
| return Uri.EscapeDataString(value); | |
| return string.Concat( | |
| value | |
| .Split(32000) | |
| .Select(c => Uri.EscapeDataString(new string(c.ToArray()))) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment