Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何将数据从URL发送到Post请求方法?_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net 如何将数据从URL发送到Post请求方法?

Asp.net 如何将数据从URL发送到Post请求方法?,asp.net,asp.net-mvc,asp.net-mvc-4,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我正在开发一个MVC4应用程序,并为我的Web服务使用Web API为android应用程序发送数据,我需要对结果进行一些测试,因此当我使用GET-Request方法时,我会将此URL放入浏览器中 http://localhost:2100/api/Accounts/LogIn?UserName=Fadi&PassWord=123456 这是我的方法 [HttpGet] public ConfrmationMessage LogIn(string UserName, strin

我正在开发一个MVC4应用程序,并为我的Web服务使用Web API为android应用程序发送数据,我需要对结果进行一些测试,因此当我使用GET-Request方法时,我会将此URL放入浏览器中

http://localhost:2100/api/Accounts/LogIn?UserName=Fadi&PassWord=123456
这是我的方法

[HttpGet]
    public ConfrmationMessage LogIn(string UserName, string PassWord)
    {
        ConfrmationMessage flag = new ConfrmationMessage();

        if (WebSecurity.Login(UserName, PassWord))
        {
            flag.status = "LogedIn";
            return flag;
        }

        else
        {
            flag.status = "The user name or password provided is incorrect.";
            return flag;
        }

    }
每件事都很好,但当我使用[HttpPost]并再次使用此URL时

http://localhost:2100/api/Accounts/LogIn?UserName=Fadi&PassWord=123456
它给了我这个错误

{"Message":"The requested resource does not support http method 'GET'."}

因此,我做了一些搜索,发现post方法使用另一种方式从URL中放入数据,但仍然无法理解如何为post方法编写正确的URL,因此需要提前提供帮助和感谢

您可以通过表单元素提交post请求,例如,这样可以添加更多属性,但您可以轻松查找这些属性

<form action="~/api/Accounts/LogIn" method="POST">
    <!--input elements here -->
</form>
$.ajax({
    url: "~/api/Accounts/LogIn",
    type: "POST",
    data: { UserName: "Fadi", PassWord: "123456" }
    success: function(result) {
        //do something when response is successful (result is the response)
    },
    error: function(jqXHR, textStatus, errorThrown) {
        //will return exception info from server
        //jqXHR is the request in xml format
        //textStatus is the description of the exception (if there is one)
        //errorThrown is the excception object thrown (if there is one)
    }
});