Windows 10 通用应用程序中的托管 api 问题 [英] Hosted api Issue in windows 10 universal app
问题描述
我创建了一个 Windows 通用应用程序,我在其中使用托管在我机器 IP 地址上的 API.当我从 VS15 或从 App 包运行应用程序时,它运行良好.但是一旦我使用应用程序包在另一台机器上运行这个应用程序,它就不起作用.同样,如果我在另一台机器的 IP 地址上托管相同的 API,它会在我的机器上停止工作.即使在这两种情况下,我都可以通过点击浏览器中的 URL 路径来访问数据.但是在手机上运行该应用包可以正常工作.
Hi I have created a windows universal app in which I am using API which is hosted on my machine's IP address. As I run the app whether from VS15 or from App package it works fine. But as soon as I run this app on another machine using app package it doesn't work. Similarly if I host the same API on another machine's IP address it stops working on my machine. Even though in both cases I can access the data via hitting the URL path in browser. But running the app package on phone works fine.
SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd.
它显示了这个错误.
这是我的 ajax 调用示例:
Here is my ajax call sample:
var ajaxRequest = $.ajax({
url: apiAddress + "Conversation/Welcome"
});
ajaxRequest.done(function (response, textStatus) {
if (textStatus == 'success') {
//success
} else {
//fail
}
});
我的 webapiconfig.cs
My 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: "*")]
放在类的上面.
I have put [EnableCors(origins: "*", headers: "*", methods: "*")]
above the class.
请帮帮我.我做错了什么?
Please help me. What I am doing wrong?
推荐答案
Manifest 中不允许私有网络访问.一旦我允许它工作正常.
Private Network Access was not allowed in Manifest. As soon as I have allowed that it worked fine.
这篇关于Windows 10 通用应用程序中的托管 api 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!