How to troubleshoot local Windows UWP (Cordova) ne

2019-08-15 05:56发布

问题:

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

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.

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.

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

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

Thanks in advance for any pointers!

[UPDATE1]

Some more information on a minimal application

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>

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

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

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.

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.

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);
         });                    
      }
    }

回答1:

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