6

My content is:

var content = new Dictionary<string, string>
{
    {"pickup_date", pickupDate.ToString("dd.MM.yyyy HH:mm")},
    {"to_city", "Victoria"},
    {"delivery_company", "4"},
    {"shop_refnum", parameters.Reference},
    {"dimension_side1", "20"},
    {"dimension_side2", "20"},
    {"dimension_side3", "20"},
    {"weight", "5"}
};

var httpContent = new FormUrlEncodedContent(content);

How can I extract content from httpContent?

Emissary
  • 9,954
  • 8
  • 54
  • 65
FireShock
  • 1,082
  • 1
  • 15
  • 25

2 Answers2

1

I had to extract data information from the request in some unit tests that I wrote. Like the other answer stated, it is possible to use the following method in the System.Net.Http namespace (I'm using .NET Core 3.1):

public static Task<NameValueCollection> ReadAsFormDataAsync(this HttpContent content);

Applied to a HttpContent instance:

var content = request.Content.ReadAsFormDataAsync();
var username = content.Result["username"];
Massimiliano
  • 615
  • 4
  • 15
-2

I found ReadAsFormDataAsync() method in System.Net.Http.Formatting:

NameValueCollection hcData = await httpContent.ReadAsFormDataAsync(cancellationToken);
FireShock
  • 1,082
  • 1
  • 15
  • 25