Pou*_*sen 1 asp.net-web-api owin
我有以下简单的控制台应用程序使用Owin SelfHost托管webapi.来自控制台本身的响应有效,但如果从fiddler尝试我只是得到与localhost的连接失败.(与浏览器相同).
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
有Console.ReadLine();using块内.没有该网络应用程序将被处置.由于您HttpClient在Web应用程序处理之前使用using块进行调用,因此可以正常运行.
| 归档时间: |
|
| 查看次数: |
875 次 |
| 最近记录: |