不允许使用返回405方法。以Get代替Post

时间:2018-07-28 12:48:50

标签: c# asp.net-web-api dotnet-httpclient

当我通过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;
            }
        }

fiddler result

0 个答案:

没有答案