Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate `x-www-form-urlencoded` content in C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text;
namespace FormUrlEncodedContentExample
{
class Program
{
static void Main(string[] args)
{
var dict = new Dictionary<string, string>
{
{ "page", "kantlista" },
{ "kod", "A0004n" },
{ "termin", "H12" },
{ "anmkod", "17113" },
{ "urval", "ant" },
{ "listVal", "namn" },
{ "method", "Sök" } // S%F6k
}; // dict
var content = new FormUrlEncodedContent(dict);
var memStream = new MemoryStream();
content.CopyToAsync(memStream).Wait();
byte[] data = memStream.GetBuffer();
var str = Encoding.UTF8.GetString(data);
Console.WriteLine(str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment