Создаем портфолио за 1 месяц
К концу месяца: 4 классных проекта в вашем портфолио! Стоимость: 100$. Подробности...
1366 of 1492 menu
◀ ▶

FormUrlEncodedContent

FormUrlEncodedContent из пары Name="abcde" даёт текст "Name=abcde". Две пары соединяются через &. Пробел в значении стал бы "%20" - в примерах пробел не используется.

Синтаксис

var pairs = new[] { new KeyValuePair<string, string>("Name", "abcde") }; var content = new FormUrlEncodedContent(pairs);

Пример

Давайте прочитать одну пару:

using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; class Program { static async Task Main() { var pairs = new[] { new KeyValuePair<string, string>("Name", "abcde") }; var content = new FormUrlEncodedContent(pairs); string res = await content.ReadAsStringAsync(); Console.WriteLine(res); } }

Результат выполнения кода:

"Name=abcde"

Пример

Давайте прочитать две пары:

using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; class Program { static async Task Main() { var pairs = new[] { new KeyValuePair<string, string>("Name", "abcde"), new KeyValuePair<string, string>("Count", "12345") }; var content = new FormUrlEncodedContent(pairs); string res = await content.ReadAsStringAsync(); Console.WriteLine(res); } }

Результат выполнения кода:

"Name=abcde&Count=12345"

Пример

Давайте проверить тип содержимого:

using System; using System.Collections.Generic; using System.Net.Http; class Program { static void Main() { var pairs = new[] { new KeyValuePair<string, string>("Name", "abcde") }; var content = new FormUrlEncodedContent(pairs); string res = content.Headers.ContentType.MediaType; Console.WriteLine(res); } }

Результат выполнения кода:

"application/x-www-form-urlencoded"

Смотрите также

← →
↑
Мы используем cookie для работы сайта, аналитики и персонализации. Обработка данных происходит согласно Политике конфиденциальности.
принять все настроить отклонить