就是說咱們本地的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的響應信息