问题
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.
It shows this error.
Here is my ajax call sample:
var ajaxRequest = $.ajax({
url: apiAddress + "Conversation/Welcome"
});
ajaxRequest.done(function (response, textStatus) {
if (textStatus == 'success') {
//success
} else {
//fail
}
});
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"));
}
I have put [EnableCors(origins: "*", headers: "*", methods: "*")]
above the class.
Please help me. What I am doing wrong?
回答1:
Private Network Access was not allowed in Manifest. As soon as I have allowed that it worked fine.
来源:https://stackoverflow.com/questions/39607881/hosted-api-issue-in-windows-10-universal-app