0

I have a Dictionary<string, object> and I like to convert this dictionary into query string parameters and then use them with HttpRequestMessage and pass it to HttpClient.

I know we can pass Dictionaly<string, string>to FormUrlEncodedContent e.g request.Content = new FormUrlEncodedContent(params) but here the value can be any type and that's why it's object.

Previously I was using RestClient where there was an option to use any kind of parameter value e.g request.AddParameter("key", "value")

Now is there any way to do that with httpClient? I want to use it in a get call so setting request.Content is not must. I can use something else e.g UriBuilder etc.

Ask
  • 3,076
  • 6
  • 30
  • 63
  • You can use `HttpUtility.ParseQueryString` along with a `UriBuilder`, [see here](https://sharplab.io/#v2:EYLgtghglgdgNAFxAJwK4wD4AEBMBGAWACgsAGAAizwDoB1AU2AG5jiA3CZcgR1XuQCe5ALzkAEggQAHAKoIoAGygIB1AAqcAzvQCKfQQGUEyWAHMAFACJLAShZFe/VQEEAJq6sAzAPbfLccktgTlt7KgBOc0dBagAVbyMTGAsbO1YiDi5gVEVXfhFyGHoAd3IZEwAhHIU85HMbYgBvYnJW8W9NBALLegAPCDApBXpqAGNvMH8Wtr0nAujVeMSzerhiAF8wvEjs3P44hOMV1PtiIA===) – canton7 Mar 11 '22 at 15:28
  • 1
    See [this](https://stackoverflow.com/a/17096289/2501279) answer – Guru Stron Mar 11 '22 at 15:41

0 Answers0