gpt4 book ai didi

javascript - Windows 10 通用应用程序中的托管 api 问题

转载 作者:行者123 更新时间:2023-11-28 05:32:05 24 4
gpt4 key购买 nike

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

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: "*")] 放在类上方。

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

最佳答案

list 中不允许专用网络访问。一旦我允许它就可以正常工作。

关于javascript - Windows 10 通用应用程序中的托管 api 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39607881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com