如何解决本地Windows UWP(Cordova)网络问题 [英] How to troubleshoot local Windows UWP (Cordova) networking issues

查看:209
本文介绍了如何解决本地Windows UWP(Cordova)网络问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Ionic / Cordova构建的Windows 10 UWP应用程序,所以我的http请求来自嵌入式webview。

I have a Windows 10 UWP application built using Ionic/Cordova, so my http requests originate from the embedded webview.

我可以在家里运行我的应用程序,或者在通过单元格连接的平板电脑上,http请求所有工作。但是,当我在任何办公机器(工作机器)上运行它时,除了本地主机之外的请求似乎被阻止。我最初认为这是网络,但是使用Wireshark,如果我只是在机器浏览器中运行它,我可以看到请求,但如果我从应用程序运行相同的话,我就看不到它们。

I can run my application at home, or on a tablet connected via cell and the http requests all work. However, when I run this on any office machine (work machines), the requests other than to local host appear to be blocked. I initially thought this was the network, however using Wireshark, I can see the request if I just run them in the machine browser, but I can't see them if I run the same from the application.

如果我通过桌面浏览器(使用Ionic服务器)运行应用程序,它也可以。它似乎只是在UWP容器中运行。

If I run the application via the desktop browser (using Ionic serve), it also works. It only seems to be when it is running in the UWP container.

由于请求没有出现在Wireshark中,我不知道如何诊断它的位置受阻。

Since the requests don't appear in Wireshark, I have no idea how to diagnose where this is getting blocked.

有没有人知道如何诊断这个(我假设当地的TCP / IP堆栈?)

Does any one have any ideas how I can diagnose this (I assume the local TCP/IP stack?)

提前感谢任何指示!

[UPDATE1]

一些关于最小应用程序的更多信息

Some more information on a minimal application

我直接从模板创建一个新的Ionic 3应用程序,我的config.xml看起来像

I create a new Ionic 3 application, straight from a template, and my config.xml looks something like

    <?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包含以下内容......

When I build to the Window package, the AppxManifest.xml includes the following...

 <Capabilities>
   <Capability Name="internetClient" />
 </Capabilities>

测试服务应该通过CORS启用,我可以通过单元格和任何其他网络连接到它我试过办公室网络除外,因为我们不知道它被阻止在哪里。我在wireshark中看不到任何东西。如果我通过Ionic服务运行相同的应用程序(因此在桌面浏览器中运行),那么我没有问题。如果我在家里安装Windows版本,我可以连接。如果我将它安装在平板电脑(例如Surface)上,那么如果表面位于办公室WIFI上则不会连接,但如果我将表面连接到手机上它就会连接。

The test service should by CORS enabled, and I can connect to it via cell, and any other network I have tried except for our office network, as we have no idea where it is being blocked. I don't see anything in wireshark. If I run the same application via Ionic serve (so running in the desktop browser), then I have no problems. If I install the Windows version at home, I can connect. If I install it on a Tablet (eg Surface), then is does NOT connect if the serface is on the office WIFI, but it DOES connect if I tether the surface to my phone.

如果我们给Surface一个固定的IP ,它似乎也可以工作。我不知道为什么固定的IP会产生影响。

IF we give the Surface a fixed IP it also then seems to work. I have no idea why the fixed IP makes a difference.

实际的测试应用程序代码如下所示(唯一的区别是办公室测试服务器的URL)。 ..

The actual test app code looks like the following (the only difference is the url to the office test server)...

    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来修复它。也许这也是你的问题?

We had the same problem and fixed it by adding the capability "privateNetworkClientServer" to the app. Perhaps that's your problem as well?

这篇关于如何解决本地Windows UWP(Cordova)网络问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆