I need an HTTP POST complex type for a web service (which I don't control). I believe that the web service was created using the old version of ASP.NET MVC. This model binds a payload formatted as form-url-encoded .
If I run the following on it, it works fine. As you can see, I manually created a collection of key / value pairs.
var values = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Username", "some-username"), new KeyValuePair<string, string>("Password", "some-password"), new KeyValuePair<string, string>("Product", "some-product") }; var content = new FormUrlEncodedContent(values); var response = new HttpClient().PostAsync(url, content).Result;
But I donβt want to do this, I just want to send complex types if I can.
var content = new ComplexType("some-username", "some-password", "some-product"); var response = new HttpClient().PostAsync(url, content).Result;
I believe there used to be an HttpRequestMessage<T> , but that was dropped in favor
HttpClient.PostAsJsonAsync<T>(T value) sends "application/json" HttpClient.PostAsXmlAsync<T>(T value) sends "application/xml"
But I donβt want to send Json or XML I want to send form-url-ecncoded without problems with converting complex types to collections of key / value pairs.
In fact, I would also like to know the answer to this question that Jaans creates (his second comment on the second answer).
Someone can advise.