Skip to content

Instantly share code, notes, and snippets.

@musoftware
Created June 23, 2018 19:25
Show Gist options
  • Save musoftware/4ca7c5c146cf491cede648b403cb74ea to your computer and use it in GitHub Desktop.
Save musoftware/4ca7c5c146cf491cede648b403cb74ea to your computer and use it in GitHub Desktop.
NameValueCollection to postData
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
public static class Extensions
{
public static string ToPostData(this NameValueCollection @this)
{
StringBuilder post = new StringBuilder();
foreach (var item in @this.AllKeys)
{
post.AppendFormat("&{0}={1}", item, HttpUtility.UrlEncode(@this[item]));
}
string postData = post.ToString().Trim('&');
return postData;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment