(2) Question two: the way to pass the parameters;
Http://www.cnblogs.com/landeanfen/p/5337072.html's supplement to this article
Test one as follows:
1) The backend code is as follows,
Note 1: There can be only one parameter in the method in the API, which cannot occur like this
public Object Post (logininfo user,string name)
Public classLogincontroller:apicontroller {[HttpPost] Public Objectpost (logininfo user) {return user.strpwd; } Public classLogininfo { Public stringstruser {Get;Set; } Public stringstrpwd {Get;Set; } }}
Send the request as follows: Send data in JSON format, write your own request header, note Contexttype:application/json, and represent the data sent in JSON format.
Note 1: The default path is set to Routetemplate: "Api/{controller}/{id}",
To be set to Routetemplate: "Api/{controller}/{action}/{id}" to request a method
The returned data received is successful.
Use the jquery test to initiate a POST request: Send data directly in the format of the object, and jquery will automatically be sent according to the format sent to the appropriate format.
The code is as follows:
<script src="Jquery-2.2.0.min.js"></script> <script>varPostData = {struser:"13443", Strpwd:"Jim" }; function Login () {$.ajax ({type:"Post", URL:"Http://localhost:61083/api/Login/Login", //contentType: "Application/json",Data:postdata, success:function (data, status) {} }); } </script>"Text-align:center;"> <div> user name: <input type="text"Id="Txt_username"Value="Admin"/></div> <div> Password: <input type="Password"Id="Txt_password"Value="123456"/></div> <div><input type="Button"Value="Login"Id="Btn_login" class="Btn-default"onclick="Javascript:login ()"/></div> </div></body>
C # WEBAPI----H5_app Background production (2)--parameter transfer (for lazy WEBAPI parameter transfer not a supplement)