【问题标题】:POST Request using ASP.NET WEB API and HttpCLient Giving Error使用 ASP.NET WEB API 和 HttpCLient 给出错误的 POST 请求
【发布时间】:2021-08-15 00:24:30
【问题描述】:

我正在尝试使用 ASP.net 进行发布请求,我正在运行我的 web api,并且我有我的应用程序,我通过我的方法调用 api,我尝试使用 Http 客户端和这是我的控制器

  public async Task<ActionResult> Create()
    {
        var user = new LutUsers();
        var jsonString = System.Text.Json.JsonSerializer.Serialize(user);
        var stringContent = new StringContent(jsonString, Encoding.UTF8, "application/json");
        var response = await client.PostAsync(client.BaseAddress + "/user/findusers", stringContent);

        Response.Write(response);
        if (response.IsSuccessStatusCode)
        {
            //Storing the response details recieved from web api   

            Response.Write("<script>alert('Connection Made successfully!');</script>")   
        }
        return View();
    }

Response.write(respon)

给我这个错误:StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent

有人可以帮我找出我做错了什么吗?谢谢

【问题讨论】:

标签: c# asp.net .net post asp.net-web-api


【解决方案1】:

我认为您确实尝试检索有关用户的一些信息,并且我认为您用于此的端点不允许使用 http 动词 POST 的请求尝试改用 GET 请求。

【讨论】:

    猜你喜欢
    • 2020-07-06
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2017-01-22
    • 2016-05-12
    相关资源
    最近更新 更多