今天用postman测试后端api,总是报错,下面是问题解决方案。
一、测试方法
public ApiResult Get(int id)
{
ApiResult result = new ApiResult();
result.data = "我是Get方法返回的数据";
result.success = true;
result.msg = "测试成功";
return result;
}
public class ApiResult
{
public bool success { get; set; }
public string msg { get; set; }
public object data { get; set; }
}
二、问题和解决
0请求:http://localhost/projectmanagement/api/user/5
在网上查了下请求要这么写:http://localhost/projectmanagement/api/user/?id=5
1 提示没有权限
去路由里面一看,前辈重新了校验规则,不知道。为了测试方法我注释的校验规则。
public static void Register(HttpConfiguration config)
{
// Web API 配置和服务
// Web API 路由
config.MapHttpAttributeRoutes();
config