私はasp.netを初めて使用します。小さな問題が発生しました。MVCプロジェクトで新しいwebapiコントローラーを作成します。このコントローラーから応答を取得しようとすると、404エラーが発生します:s
使用されるコントローラーのコードは次のとおりです。
public class SampleController : ApiController
    {
        [HttpPost]
        public string Auth(string number, string password)
        {
            ....
        }
        [HttpPost]
        public string SendSms(string smsTo, string content)
        {
            ....
        }
    }
WebApiConfig :
public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}
そしてここにコード c# :
using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:66893");
                var content = new FormUrlEncodedContent(new[] 
            {
                new KeyValuePair<string, string>("number", "login"),
                new KeyValuePair<string, string>("password", "password")
            });
                var result = client.PostAsync("/api/sms/auth", content).Result;
                string resultContent = result.Content.ReadAsStringAsync().Result;
                Console.WriteLine(resultContent);
            }
XHR ポスターで localhost:66893/api/sms/auth?number=xxx&password=xxx を試すと、結果が得られます:s
plzはthxをたくさん助けてください