相关疑难解决方法(0)

ASP.NET WebApi:(405)方法不允许

我有一个Web Api控制器.它表现得很奇怪.当我使用PostMan时,我可以在Web Api上访问POST方法,但是当我从.net使用HttpWebRequest时,它返回(405)Method Not Allowed.我把Web Api代码放在这里:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace MyProject.Controllers
{
    public class TestController : ApiController
    {
        [HttpPost]
        public int buy(OrderResult value)
        {
            try
            {
                if (value.InvoiceDate != null && value.Result == 1)
                {
                    return 0;
                }
            }
            catch{}

            return -1;
        }
    }

    public class OrderResult
    {
        public int Result { get; set; }
        public long InvoiceNumber { get; set; }
        public string InvoiceDate { get; …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc asp.net-web-api

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

asp.net-web-api ×1