就是说咱们本地的http://localhost:49708/api/test能够经过 这个东西来访问(懒得挂载iis,固然它的强大可不这些,因为测试出了问题 出记录一下)html
首先去Nuget包里找到Microsoft.AspNet.WebApi.OwinSelfHost这个东西web
而后建立一个控制台程序api
class Program { static void Main(string[] args) { try { string baseAddress = "http://localhost:49708/"; // Start OWIN host 这段注释是官网提供的代码怎么弄都用错,下面没打注释的是能够运行的
//地址:https://docs.microsoft.com/en-us/aspnet/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api //using (WebApp.Start<Startup>(url: baseAddress)) //{ // // Create HttpCient and make a request to api/values // HttpClient client = new HttpClient(); // var response = client.GetAsync(baseAddress + "api/test").Result; // Console.WriteLine(response); // Console.WriteLine(response.Content.ReadAsStringAsync().Result); // Console.ReadLine(); //} HttpClient client = new HttpClient(); var response = client.GetAsync(baseAddress + "api/test").Result; Console.WriteLine(response); Console.WriteLine(response.Content.ReadAsStringAsync().Result); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(e); throw; } } }
//资料参考:http://www.cnblogs.com/TianFang/p/3728760.html
//下面就是webapi的响应信息