【问题标题】:Fiddler: The connection to 'localhost' failed. with owin selfhostFiddler:与“localhost”的连接失败。与 owin selfhost
【发布时间】:2014-09-05 20:51:42
【问题描述】:

我有以下使用 Owin SelfHost 托管 webapi 的简单控制台应用程序。控制台本身的响应有效,但如果从提琴手尝试,我只是连接到本地主机失败。 (与浏览器相同)。

class Program
    {
        static void Main()
        {
            string baseAddress = "http://localhost:34300/";
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("da-dk");
            // Start OWIN host 
            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/GpsPositions").Result;

                Console.WriteLine(response);
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                Console.WriteLine("Listening on " + baseAddress);
            }

            Console.ReadLine();
        } 
    }

我错过了什么吗?

【问题讨论】:

    标签: asp.net-web-api owin


    【解决方案1】:

    在 using 块中有Console.ReadLine();。没有该网络应用程序将被处置。由于您在处理 Web 应用程序之前在 using 块中使用 HttpClient 进行调用,因此它可以工作。

    【讨论】:

      猜你喜欢
      • 2015-02-24
      • 2023-01-30
      • 2021-06-20
      • 2016-01-15
      • 2017-07-21
      • 2013-09-29
      • 2013-09-29
      • 2015-08-19
      • 1970-01-01
      相关资源
      最近更新 更多