【问题标题】:could not establish a secure connection with my given url in my app无法在我的应用程序中与我给定的 url 建立安全连接
【发布时间】:2016-03-15 09:27:44
【问题描述】:

我有一个包含隐藏值的表单,提交表单时需要将其发布到 url。 该网址用于信用卡支付,出于安全目的, 因此,当尝试使用我的应用程序打开 url 并使用它发布隐藏值时,它无法建立安全连接并且应用程序崩溃。 但是当我在我的电脑浏览器中执行此操作时,它工作正常,没有错误。

这是我的表格:

<form name="hidden_form" id="hidden_form" action="{{ bookings.payment.ACSUrl }}" method="POST">
  <input type="hidden" name="PaReq" value="{{ bookings.payment.PaReq }}" />
  <input type="hidden" name="TermUrl" value="{{ bookings.payment.TermUrl }}" />
  <input type="hidden" name="MD" value="{{ bookings.payment.md }}" />
</form>

网址是: https://webapp.securetrading.net/acs/visa.cgi 使用我的应用程序(phonegap) 提交表单时需要时间并点击 url 但错误提示无法建立安全连接,然后是 url 和应用程序崩溃。 需要帮助 我希望每个人都能明白我想说什么

【问题讨论】:

    标签: jquery angularjs cordova phonegap-desktop-app


    【解决方案1】:

    对于 phonegap,您需要添加白名单插件(它曾经在核心中,所以您可能已经拥有它):

    https://github.com/apache/cordova-plugin-whitelist

    此处列出了帮助文档:

    http://docs.build.phonegap.com/en_US/configuring_access_elements.md.html

    安装插件后,您还需要在 config.xml 中添加这一行:

    <access origin="https://securetrading.net/" subdomains="true"/>
    

    编辑:

    为了能够在不打开设备网络浏览器的情况下提交表单,您需要通过 JavaScript 提交表单。由于您标记了您正在使用 jQuery,因此这里是执行此操作的代码:

        $(document).on('submit', 'form.hidden_form', function() {            
                $.ajax({
                    url     : $(this).attr('action'),
                    type    : $(this).attr('method'),
                    dataType: 'json',
                    data    : $(this).serialize(),
                    success : function( data ) {
                                 alert('Submitted');
                    },
                    error   : function( xhr, err ) {
                                 alert('Error');     
                    }
                });    
    
    
    return false;
        });
    

    编辑 - 4/12:

    这是一个完全不同的例子。我从您的 URL 收到 500 错误代码,因为我假设我发送了无效数据,但它会发送到站点并传递数据:

        <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="mobile-web-app-capable" content="yes" />
        <meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
        <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
        <link href='https://fonts.googleapis.com/css?family=Roboto:400,300italic,300,400italic,500,700,700italic,500italic' rel='stylesheet' type='text/css'>
        <title>Onsen UI Forum Help by Munsterlander</title>
    
        <link rel="stylesheet" href="https://cdn.rawgit.com/OnsenUI/OnsenUI-dist/2.0.0-beta.8/css/onsenui.css" type="text/css" media="all" />
        <link rel="stylesheet" href="https://cdn.rawgit.com/OnsenUI/OnsenUI-dist/2.0.0-beta.8/css/onsen-css-components.css">
        <script src="https://cdn.rawgit.com/OnsenUI/OnsenUI-dist/2.0.0-beta.8/js/onsenui.js"></script>
        <script src="components/loader.js"></script>
    
        <script>
            function formHelp(){
                my_form=document.createElement('FORM');
                my_form.name='myForm';
                my_form.method='POST';
                my_form.action='https://webapp.securetrading.net/acs/visa.cgi';
    
                my_tb=document.createElement('INPUT');
                my_tb.type='HIDDEN';
                my_tb.name='PaReq';
                my_tb.value='000';
                my_form.appendChild(my_tb);
    
                my_tb=document.createElement('INPUT');
                my_tb.type='HIDDEN';
                my_tb.name='TermUrl';
                my_tb.value='000';
                my_form.appendChild(my_tb);
    
                my_tb=document.createElement('INPUT');
                my_tb.type='HIDDEN';
                my_tb.name='MD';
                my_tb.value='000';
                my_form.appendChild(my_tb);
    
                document.body.appendChild(my_form);
                my_form.submit();
            }
    
        </script>    
    </head>
    
    <body>
    
    <ons-tabbar id="myNav">
      <ons-tab page="home.html" active="true">
        <ons-icon icon="ion-home"></ons-icon>
        <span style="font-size: 14px">Home</span>
      </ons-tab>
      <ons-tab page="fav.html">
        <ons-icon icon="ion-star"></ons-icon>
        <span style="font-size: 14px">Favorites</span>
      </ons-tab>
      <ons-tab page="settings.html">
        <ons-icon icon="ion-gear-a"></ons-icon>
        <span style="font-size: 14px">Settings</span>
      </ons-tab>
    </ons-tabbar>
    <ons-template id="home.html">
      <p>Home</p>
      <ons-button onclick="formHelp()">Submit JS Form</ons-button>
      <div style="padding:10px;">    
      </div>
      <form name="hidden_form" id="hidden_form" action="https://webapp.securetrading.net/acs/visa.cgi" method="POST">
          <input type="hidden" name="PaReq" value="000" />
          <input type="hidden" name="TermUrl" value="000" />
          <input type="hidden" name="MD" value="000" />
          <input type="submit" name="submit" value="Submit Form"/>
        </form>
    </ons-template>
    <ons-template id="fav.html">
      <p>Fav</p>
    </ons-template>
    <ons-template id="settings.html">
      <p>Settings</p>
    </ons-template>
    
    </body>
    </html>
    

    这里是配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <widget xmlns="http://www.w3.org/ns/widgets" id="com.example.helloworld" version="1.0.0">
      <name>Onsen 2.0 Quick Start</name>
      <description/>
      <author/>
      <content src="index.html"/>
      <access origin="*"/>
      <allow-navigation href="*"/>
      <allow-intent href="itms:*"/>
      <allow-intent href="itms-apps:*"/>
      <preference name="DisallowOverscroll" value="true"/>
      <preference name="Orientation" value="default"/>
      <preference name="loglevel" value="DEBUG"/>
      <preference name="AndroidLaunchMode" value="singleTop"/>
      <preference name="ErrorUrl" value=""/>
      <preference name="Fullscreen" value="false"/>
      <preference name="KeepRunning" value="true"/>
      <preference name="SplashScreen" value="screen"/>
      <preference name="SplashScreenDelay" value="1000"/>
      <preference name="AllowInlineMediaPlayback" value="false"/>
      <preference name="AutoHideSplashScreen" value="true"/>
      <preference name="BackupWebStorage" value="cloud"/>
      <preference name="EnableViewportScale" value="false"/>
      <preference name="FadeSplashScreen" value="true"/>
      <preference name="FadeSplashScreenDuration" value=".25"/>
      <preference name="KeyboardDisplayRequiresUserAction" value="true"/>
      <preference name="MediaPlaybackRequiresUserAction" value="false"/>
      <preference name="ShowSplashScreenSpinner" value="false"/>
      <preference name="SuppressesIncrementalRendering" value="false"/>
      <preference name="TopActivityIndicator" value="gray"/>
      <preference name="GapBetweenPages" value="0"/>
      <preference name="PageLength" value="0"/>
      <preference name="PaginationBreakingMode" value="page"/>
      <preference name="PaginationMode" value="unpaginated"/>
      <feature name="LocalStorage">
        <param name="ios-package" value="CDVLocalStorage"/>
      </feature>
      <preference name="UIWebViewDecelerationSpeed" value="normal"/>
      <preference name="monaca:AndroidIsPackageNameSeparate" value="false"/>
      <preference name="monaca:targetFamilyiPhone" value="1"/>
      <preference name="monaca:targetFamilyiPad" value="1"/>
    </widget>
    

    这些只是快速启动应用程序,并且似乎都可以与您的网站进行良好的通信。我认为您可能没有的最重要的部分是:

    <access origin="*"/>
    <allow-navigation href="*"/>
    

    基础包中只安装了monaca插件、splashscreen插件、whitelist插件。

    【讨论】:

    • 我确实添加了这个访问标签和白名单我已经在那里,但错误仍然存​​在,你想看看我的 config.xml 吗? @Munsterlander
    • 你还有什么想法吗:当我提交表单时,表单的操作属性会将我带到给定的 url,并使用 inappbrowser 打开我要检查的是我可以处理使用外部浏览器提交表单@munsterlander ?
    • 我已经编辑了我的答案,以便为您提供表单提交的代码。这可能还会解决您的白名单错误,因为我没有意识到您要跨浏览器 - 一个完全不同的问题。
    • 我还需要重定向到 url,我必须将所有责任交给正在发布的 url,我认为 ajax req 不会帮助我,它只能通过表单发布到 url 来实现并且出于安全目的,该 url 应该在外部打开,因为默认浏览器给了我无法建立的安全连接。 @munsterlander
    • 混合应用程序只不过是一个为插件包装的迷你网络浏览器。当表单发布到您的 URL 时,它会打开设备 Web 浏览器。目前(仅作为示例),您正试图让 Firefox 将信息传递给 Internet Explorer 并来回传递。这就是您收到错误的原因。因此,您必须使用 InAppBrowser 在您的应用程序中打开 URL。因此,这解决了跨浏览器错误和安全问题。查看:developer.telerik.com/featured/… 了解更多信息。
    猜你喜欢
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-10-11
    相关资源
    最近更新 更多