this issue is trace Http Call processor and method
HttpClient, can using Named Client
404:
this URI is specify, it's BaseAddress must be endwith /
and relative uri must not be start with /
400
DateTime is strange in .net framework, it must be formatted like this /Date(12346464)/
so must SerializeObject by DateFormatHandling.MicrosoftDateFormat
500
can call target service success, but service error
sample
// startip.cs
services.AddHttpClient(ClientsConstants.TABLE_SERVICE_CLIENT, client =>
{
client.BaseAddress = new Uri(TableServiceConfig.GetSection("BaseUrl").Value);
// this will get Misused header name error
// client.DefaultRequestHeaders.Add(RequestHeaders.CONTENT_TYPE, RequestHeaders.JSON_CONTENT);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.Timeout = TimeSpan.FromMilliseconds(Convert.ToInt32(TableServiceConfig.GetSection("Timeout").Value));
});
// service class
var jsonBody = JsonUtil.SerializeObject(new AutoRollRequestBody(tableId, gamingDay), DateFormatHandling.MicrosoftDateFormat);
var client = _clientFactory.CreateClient(ClientsConstants.TABLE_SERVICE_CLIENT);
StringContent content = new StringContent(jsonBody);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = client.PostAsync(ServiceURLConstants.TABLE_SERVICE_PATH, content).Result;
response.EnsureSuccessStatusCode();
return JsonUtil.DeserializeObject<ReceiveTableInventory>(response.Content.ReadAsStringAsync().Result);
RestClient: same issue with HttpClient
request body: addJsonBody()
sample
public static IRestResponse Post(string requestPath, int timeout, object jsonBody, IDictionary<string, string> headerParams, string clientPath)
{
var request = new RestRequest(requestPath, Method.POST) { Timeout = timeout };
request.AddHeader(RequestHeaders.CONTENT_TYPE, RequestHeaders.JSON_CONTENT);
request.RequestFormat = DataFormat.Json;
if (headerParams != null && headerParams.Count > 0)
{
foreach (string key in headerParams.Keys)
{
request.AddHeader(key, headerParams[key]);
}
}
if (jsonBody != null)
{
request.AddJsonBody(jsonBody);
}
var client = new RestClient(clientPath);
return client.Execute(request);
}
core: so can get request detail by fiddler
this issue is trace Http Call processor and method
HttpClient, can using
Named Client
404:
/
/
400
DateFormatHandling.MicrosoftDateFormat
500
sample
RestClient: same issue with HttpClient
request body:
addJsonBody()
sample
reference