Now if I want to send http content I use dictionary and then convert it into http content and then I send in, but I want to convert a object to a http content directly.
What I do now:
var contentDictionary = new Dictionary<string, string>()
{
{ "customerId",customerId.ToString()}
};
var httpContentData = new FormUrlEncodedContent(contentDictionary );
var request= await _httpClient.PostAsync(url,httpContentData );
what I want to do but I don't know how to do it :
var obj =new custome(){CustomerId=customerId};
...
//do something
...
var request= await _httpClient.PostAsync(url,httpContent );
I used some kind of syntax but it did not work for me and now I'm looking for some kind of NuGet or libary or syntax that can help me in this case.
http contentcovers all possible content types. What does the remote URL expect? A FORM post? JSON? A CSV file? Some other format?.PostAsJsonAsync(url,customer), or you can serialize thecustomerobject to a JSON string and wrap it in a JsonContent.FormUrlEncodedContent? There's a similar question: Build URL encoded query from model object for HttpClient. The answers show how to use reflection to read all properties or use a JSON serializer to help handle complex objects