Windows 10 Universal App中的托管API问题

编程入门 行业动态 更新时间:2024-10-28 00:16:18
本文介绍了Windows 10 Universal App中的托管API问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我创建了一个Windows通用应用程序,其中使用的API托管在计算机的IP地址上.无论是从VS15还是从应用程序包运行应用程序,它都可以正常运行.但是,一旦我使用应用程序包在另一台计算机上运行此应用程序,它就无法正常工作.同样,如果我在另一台计算机的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:"*",标头:"*",方法:"*")] .

请帮助我.我在做什么错了?

Please help me. What I am doing wrong?

推荐答案

清单中不允许进行私有网络访问.一旦我允许它运行正常.

Private Network Access was not allowed in Manifest. As soon as I have allowed that it worked fine.

更多推荐

Windows 10 Universal App中的托管API问题

本文发布于:2023-11-06 04:17:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Windows   Universal   API   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!