one api returns: 发送网络服务请求时不允许的方法

one api returns: Method not allowed when sending webservice request

我有一个可用的网络服务 运行,我只有一个 api 调用,它运行完美。
所以现在我想添加另一个 api 但我无法让这个工作,当我在浏览器中尝试时它一直返回这个错误

The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource

如果我在我的 testclient c# 项目中尝试它 returns Method not allowed

我所做的与已经工作的 api 完全相同,那么这个令人讨厌的错误的原因是什么?

工作中的代码 api

public class SCSController : ApiController
{
    // GET: SCS
    public HttpResponseMessage AddDriverPayments(DriverPayment driverPayments)
        {
            HttpResponseMessage result = null;

            try
            {
                DriverPaymentResponse response = new DriverPaymentResponse() { PaymentID = driverPayments.newID, SCS_ID = driverPayments.sCS_ID };
                result = Request.CreateResponse(response);
            }
            catch (Exception ex)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent("error"),
                    ReasonPhrase = ex.Message
                };
                throw new HttpResponseException(resp);
            }

            return result;
        }

来自无效的代码 api

    public class VLAController : ApiController
    {

        // GET: VLA
        public HttpResponseMessage GetAppLogin(AppLoginRequest appLoginRequest)
        {
            HttpResponseMessage result = null;

            try
            {
                //VLADataBase db = new VLADataBase();
                //AppLoginResponse response = db.GetAppLogin(appLoginRequest);
                AppLoginResponse response = new AppLoginResponse() { Authorized = true, TruckID = 123 };
                result = Request.CreateResponse(response);
            }
            catch (Exception ex)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content = new StringContent("error"),
                    ReasonPhrase = "fout: " + ex.Message
                };
                throw new HttpResponseException(resp);
            }

            return result;
        }

我如何在我的测试客户端中调用它

这就是我对工作的称呼api

  string JsonData = JsonConvert.SerializeObject(payments);
            System.Net.Http.StringContent restContent = new StringContent(JsonData, Encoding.UTF8, "application/json");
            HttpClient client = new HttpClient();
            try
            {
                var response = await client.PostAsync(comboBoxEditWebService.Text, restContent);

                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStringAsync();
                    DriverPaymentResponse Result = JsonConvert.DeserializeObject<DriverPaymentResponse>(stream);

                    textBoxResult.Text = Result.SCS_ID + " " + Result.PaymentID;
                }
                else
                {
                    textBoxResult.Text = response.StatusCode + " " + response.ReasonPhrase;
                }
            }
            catch (Exception ex)
            {
                textBoxResult.Text = ex.Message;
            }

这就是我所说的不工作api

   string JsonData = JsonConvert.SerializeObject(appLoginRequest);
            System.Net.Http.StringContent restContent = new StringContent(JsonData, Encoding.UTF8, "application/json");
            HttpClient client = new HttpClient();
            try
            {
                var response = await client.PostAsync(comboBoxEdit1.Text, restContent);

                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStringAsync();
                    AppLoginResponse Result = JsonConvert.DeserializeObject<AppLoginResponse>(stream);

                    textBox1.Text = Result.Authorized.ToString() + " " + Result.TruckID.ToString(); //Result.SCS_ID + " " + Result.PaymentID;
                }
                else
                {
                    textBox1.Text = response.StatusCode + " " + response.ReasonPhrase;
                }
            }
            catch (Exception ex)
            {
                textBox1.Text = ex.Message;
            }

我必须注意,两个 api 在不同的单元中,在不同的控制器中,这可能是个问题吗?

那么我怎样才能解决这个问题,这样我就可以同时使用 api?

[HttpPost] 装饰端点就成功了(请参阅评论中的对话)。