6.5、HttpPost请求测试(必须使用模拟post请求的工具)
必须Postman或其它工具访问:
7、跨域配置
只需要在【Web.config】的 <system.webServer>标签内添加如下编码即可:
<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="*" /> <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> </customHeaders> </httpProtocol>
8、 测试【Ajax】的Get请求
HTML代码:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(document).ready(function () { $.ajax({ url: "http://localhost:5833/api/Test/GetInfo", type: "Get", dataType: "json", success: function (data) { document.write(data["code"]); document.write("<hr/>"); document.write(data["message"]); document.write("<hr/>"); document.write(data["result"]); } }); }); </script>
效果: