当我通过httpclient拨打电话时,收到奇怪的行为。答案是405方法不允许。检查文件,将请求报告为GET。怎么可能呢?
private HttpResponseMessage Save(string value1, string value2, int value3)
{
var jsonModel = new CreateCustomerRequest()
{
Value1= value1,
Value2= value2,
Value3= value3
};
var serializeObject = JsonConvert.SerializeObject(jsonModel);
var baseurl = configuration.GetValueFromAppSettings("baseUrl");
using (var client = new HttpClient())
{
var payLoad = new StringContent(serializeObject, Encoding.UTF8, "application/json");
client.BaseAddress = new Uri(baseurl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return client.PostAsync("api/Customer", payLoad).Result;
}
}