forked from reincubate/ricloud-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
28 lines (26 loc) · 1.2 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Reincubate.ricloud {
/// <summary>
/// Helper class for utilities relating to iCloud data extraction
/// </summary>
public class Utils {
/// <summary>
/// Utility function to convert a Dictionary of string objects into a suitably formatted HTTP POST string
/// </summary>
/// <param name="postVariables">Dictionary of variables to encode</param>
/// <returns>HTTP encoded string suitable for specifying as data for an HTTP POST request</returns>
public static string dictionaryToPostString( Dictionary<string, string> postVariables ) {
StringBuilder postString = new StringBuilder();
foreach (KeyValuePair<string, string> pair in postVariables) {
if (pair.Key != null && pair.Key != "" && pair.Value != null && pair.Value != "" )
postString.Append(Uri.EscapeDataString(pair.Key)).Append("=").Append(Uri.EscapeDataString(pair.Value)).Append("&");
}
if ( postString.Length > 0 )
postString.Length -= 1;
return postString.ToString();
}
}
}