0

I need to pass parameters for filtering to ASP.NET Core REST API Server using HttpClient.

Filter contains complex data type. I used to pass data by HttpPost, but it not suitable for CRUD concept.

How can I send complex data type as json object in HttpGet request?

Tseng
  • 61,549
  • 15
  • 193
  • 205
Atlantis
  • 725
  • 7
  • 26

1 Answers1

0

You can do it by defining your own Get method e.g.:

static async Task<HttpResponseMessage> GetAsync(this HttpClient client, string uri, HttpContent content, CancellationToken cancelToken)
{
    var request = new HttpRequestMessage(new HttpMethod("GET"), uri)
    {
        Content = content
    };
    return await client.SendAsync(request, cancelToken);
}

However! It is not recommended to do so, read about it here: HTTP GET with request body

The better solution would be to convert your complex object into URL parameters

Community
  • 1
  • 1
Mats391
  • 1,199
  • 7
  • 12