在Windows 10通用应用程序中托管api问题

问题描述:

您好我已经创建了一个Windows通用应用程序,其中我使用托管在我的计算机IP地址上的API。当我运行应用程序,无论是从VS15还是从应用程序包,它都可以正常工作。但只要我在使用应用程序包的另一台机器上运行此应用程序,它不起作用。 同样,如果我在另一台机器的IP地址上托管相同的API,它将停止在我的机器上工作。 即使在这两种情况下,我都可以通过浏览器中的URL路径访问数据。 但在手机上运行应用程序包效果很好。在Windows 10通用应用程序中托管api问题

SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd. 

它显示此错误。

这里是我的ajax调用示例:

var ajaxRequest = $.ajax({ 
      url: apiAddress + "Conversation/Welcome" 
     }); 
     ajaxRequest.done(function (response, textStatus) { 
      if (textStatus == 'success') { 
       //success 
      } else { 
       //fail 
      } 
     }); 

我webapiconfig.cs

public static void Register(HttpConfiguration config) 
     { 
      // Web API routes, configuration and services 
      config.EnableCors(); 
      config.MapHttpAttributeRoutes(); 
      config.Routes.MapHttpRoute(
       name: "DefaultApi", 
       routeTemplate: "api/{controller}/{action}/{id}", 
       defaults: new { id = RouteParameter.Optional } 
      ); 
      config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); 
     } 

我已经把[EnableCors(origins: "*", headers: "*", methods: "*")]类以上。

请帮帮我。我做错了什么?

+0

Manifest中不允许私人网络访问。只要我允许它工作正常。 – Sonali

Manifest中不允许私人网络访问。只要我允许它工作正常。