Currently I am working with HttpClient, but I am unable to understand which parameter I have to pass, i.e. string content or bytes content.
Code 1:
ModelAttribute modelAttribute = new ModelAttribute {Id=modelId, Type="new", MakeId = makeId};
RefreshWrapper refreshWrapper = new RefreshWrapper(){ ModelAttribute = new List<ModelAttribute>{modelAttribute}};
var jsonInString = JsonConvert.SerializeObject(refreshWrapper);
string baseUrl = string.Format("http://localhost:8090/api/abc");
var buffer = System.Text.Encoding.UTF8.GetBytes(jsonInString);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpClient client = new HttpClient();
client.BaseAddress = new System.Uri(baseUrl);
var result=client.PostAsync("", byteContent).Result;
Code 2:
ModelAttribute modelAttribute = new ModelAttribute {Id=modelId, Type="new", MakeId = makeId};
RefreshWrapper refreshWrapper = new RefreshWrapper(){ ModelAttribute = new List<ModelAttribute>{modelAttribute}};
var jsonInString = JsonConvert.SerializeObject(refreshWrapper);
string baseUrl = string.Format("http://localhost:8090/apabci/");
HttpClient client = new HttpClient();
client.PostAsync(baseUrl, new StringContent(jsonInString, Encoding.UTF8, "application/json"));
Which one is better?
StringContentwill be converted to an array of bytes anyway), answers to this question are likely to be opinions, rather than objective facts.