我有一个使用 Ionic/Cordova 构建的 Windows 10 UWP 应用程序,因此我的 http 请求来自嵌入式 webview。
我可以在家里或通过手机连接的平板电脑上运行我的应用程序,并且 http 请求都可以正常工作。但是,当我在任何办公室机器(工作机器)上运行它时,除了本地主机之外的请求似乎被阻止了。我最初以为这是网络,但是使用 Wireshark,如果我只是在机器浏览器中运行它们,我可以看到请求,但如果我从应用程序运行相同的内容,我就看不到它们。
如果我通过桌面浏览器(使用 Ionic 服务)运行该应用程序,它也能正常工作。似乎只有在 UWP 容器中运行时才会出现。
由于请求没有出现在 Wireshark 中,我不知道如何诊断这是在哪里被阻止的。
我如何诊断这个(我假设是本地 TCP/IP 堆栈?)
更新1
关于最小应用程序的更多信息
我直接从模板创建了一个新的 Ionic 3 应用程序,我的 config.xml 看起来像
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyApp</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="*" />
<feature name="http://api.phonegap.com/1.0/network" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="windows-target-version" value="10.0" />
<platform name="android">
...
<platform name="ios">
...
</platform>
<engine name="windows" spec="^5.0.0" />
<plugin name="cordova-plugin-console" spec="^1.0.5" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-wkwebview-engine" spec="^1.1.3" />
</widget>
当我构建到 Window 包时,AppxManifest.xml 包含以下内容...
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
测试服务应该由 CORS 启用,我可以通过手机和我尝试过的任何其他网络连接到它,除了我们的办公室网络,因为我们不知道它在哪里被阻止。我在 wireshark 中没有看到任何东西。如果我通过 Ionic serve 运行相同的应用程序(因此在桌面浏览器中运行),那么我没有问题。如果我在家里安装 Windows 版本,我可以连接。如果我将它安装在平板电脑(例如 Surface)上,如果 serface 在办公室 WIFI 上,则不会连接,但如果我将 Surface 连接到我的手机,它会连接。
如果我们给 Surface 一个固定 IP,它似乎也可以工作。我不知道为什么固定 IP 会有所不同。
实际的测试应用程序代码如下所示(唯一的区别是办公室测试服务器的 url)...
export class HomePage {
public result : any;
public url : string;
constructor(public navCtrl: NavController, private http: Http) {
this.url='http://mytesturl';
}
public onClick() : void {
this.http.get(this.url).subscribe(res => {
this.result = res.statusText;
console.log(res);
}, (error : Response) => {
let json = error.json();
this.result = `failed ${error.statusText}`;
console.log(error);
});
}
}
最佳答案
我们遇到了同样的问题,并通过向应用程序添加功能“privateNetworkClientServer”来解决它。也许这也是您的问题?
关于windows - 如何解决本地 Windows UWP (Cordova) 网络问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46480462/