Hosted api Issue in windows 10 universal app

痞子三分冷 提交于 2020-01-05 05:05:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!