VS2015 Cordova Tools:在config.xml中从windows 8.1切换到windows 10时,



非常简单,我一直在使用VS 2015的Cordova工具编写一个应用程序。它在Windows版本的默认Windows 8.1设置下工作得很好。然而,当我在config.xml中切换到Windows 10时,我想利用页面导航速度的显着提高。然而,一旦我这样做,我所有的帖子与WinJS的xhr远程url立即失败,除了短语"安全错误"。当我切换到Windows 8.1

时,相同的代码工作正常

其他人有过这样的经历吗?

我试过从"远程模式"切换回"本地模式"添加

到我的config.xml,但它似乎不影响这个错误。

edit我使用的确切代码(typescript):

var url = "https://api.twitter.com/oauth/request_token";
 return WinJS.xhr({
            url: url,
            type: 'POST',
            headers: {
                "Content-type": "application/x-www-form-urlencoded",
                "Authorization": authorizationHeader
            },
            data: ""
        }).then((success) => { 
 },(error)=>{
 });
生成AppxManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<Package IgnorableNamespaces="uap mp build" xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
  <!--
    THIS PACKAGE MANIFEST FILE IS GENERATED BY THE BUILD PROCESS.
    Changes to this file will be lost when it is regenerated. To correct errors in this file, edit the source .appxmanifest file.
    For more information on package manifest files, see http://go.microsoft.com/fwlink/?LinkID=241727
  -->
  <Identity Name="redacted" Publisher="redacted" Version="1.0.0.0" ProcessorArchitecture="x86" />
  <mp:PhoneIdentity PhoneProductId="550b2480-3bd3-11e5-86b0-855663c85edc" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
  <Properties>
    <DisplayName>redacted</DisplayName>
    <PublisherDisplayName>L McPherson</PublisherDisplayName>
    <Logo>imagesStoreLogo.png</Logo>
  </Properties>
  <Dependencies>
    <TargetDeviceFamily MaxVersionTested="10.0.10240.0" MinVersion="10.0.10240.0" Name="Windows.Universal" />
  </Dependencies>
  <Resources>
    <Resource Language="EN-US" />
  </Resources>
  <Applications>
    <Application Id="io.cordova.myappfbb75e" StartPage="ms-appx-web:///www/index.html">
      <uap:VisualElements BackgroundColor="#464646" Description="CordovaApp" DisplayName="redacted" Square150x150Logo="imagesSquare150x150Logo.png" Square44x44Logo="imagesSquare44x44Logo.png">
        <uap:SplashScreen Image="imagessplashscreen.png" />
        <uap:DefaultTile ShortName="redacted" Square310x310Logo="imagesSquare310x310Logo.png" Square71x71Logo="imagesSquare71x71Logo.png" Wide310x150Logo="imagesWide310x150Logo.png" />
      </uap:VisualElements>
      <uap:ApplicationContentUriRules>
        <uap:Rule Match="ms-appx-web:///" Type="include" WindowsRuntimeAccess="all" />
      </uap:ApplicationContentUriRules>
    </Application>
  </Applications>
  <Capabilities>
    <Capability Name="internetClient" />
    <DeviceCapability Name="webcam" />
    <DeviceCapability Name="microphone" />
  </Capabilities>
  <build:Metadata>
    <build:Item Name="SharedGUID" Value="9ebdb27f-d75b-4d8c-b53f-7be4a1fe89f9" />
    <build:Item Name="CodeSharingProject" Value="248F659F-DAC5-46E8-AC09-60EC9FC95053" />
    <build:Item Name="VisualStudio" Version="14.0" />
    <build:Item Name="VisualStudioEdition" Value="Microsoft Visual Studio Community 2015" />
    <build:Item Name="OperatingSystem" Version="10.0.10532.0 (th2_release.150822-1406)" />
    <build:Item Name="Microsoft.Build.AppxPackage.dll" Version="14.0.23121.0" />
    <build:Item Name="ProjectGUID" Value="20968146-3a8e-4e05-96b7-33eedd330850" />
    <build:Item Name="OptimizingToolset" Value="ilc.exe" />
    <build:Item Name="TargetRuntime" Value="AppHost" />
    <build:Item Name="ilc.exe" Version="1.0.23117.00 built by: PROJECTNREL" />
    <build:Item Name="MakePri.exe" Version="10.0.10240.16384 (th1.150709-1700)" />
  </build:Metadata>
</Package>

我终于弄明白了。我认为我的部分问题是我使用了旧项目的代码/html片段,而没有使用新项目提供的默认值。在任何情况下,在Cordova生成的index.html文件的头部有一个新行:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

如果我没记错的话,Windows 8.1不会计算这一行。但是,Windows 10 支持。当我试图插入'connect-src'作为其中一个指令时,我得到了一个错误,所以我只是修改了默认的src指令:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com https://api.twitter.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

因为我想从https://api.twitter.com获取内容,所以我必须在允许的情况下特别包含它。

另外,我不确定它是否有帮助或什么也没做,但我排除了winstore- jspat .js shim。Windows 10不需要。

一般来说,您使用的XHR代码应该可以工作。我添加这个示例是为了显示XHR post数据正在工作。我使用的是WinJS 4.0 http://try.buildwinjs.com/download/GetWinJS/,尽管任何新版本都应该可以正常工作。您是否升级了您正在使用的WinJS版本?

function success(evt) {
}
function error(evt) {
}
WinJS.xhr({
    type: "post",
    url: "http://httpbin.org/post",
    headers: { "Content-type": "application/x-www-form-urlencoded" },
    data: JSON.stringify({ myData: "postDataStringValue" })
}).then(success, error);

最新更新