【发布时间】:2018-08-03 18:56:00
【问题描述】:
我有一个使用 Ionic/Cordova 构建的 Windows 10 UWP 应用程序,因此我的 http 请求来自嵌入式 web 视图。
我可以在家中运行我的应用程序,也可以在通过单元连接的平板电脑上运行我的应用程序,并且 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);
});
}
}
【问题讨论】:
-
您是否启用了
internetClientServer功能?你能提供一个minimal reproducible example吗? -
在帖子中添加了更多信息。我需要知道的最重要的事情是是否有任何测试工具来跟踪阻止它的原因?有什么东西挡住了它。
-
另外,请求永远不会到达服务器。我在 IIS 日志中看不到请求的证据。日志处于活动状态,因为我可以看到应用在工作设备上运行时发出的请求。
标签: windows cordova http ionic-framework uwp