Skip to content

Instantly share code, notes, and snippets.

@nakov
Created February 18, 2021 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakov/9d840e6a499e7d54a512932a26c69e7a to your computer and use it in GitHub Desktop.
Save nakov/9d840e6a499e7d54a512932a26c69e7a to your computer and use it in GitHub Desktop.
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