2016-08-02 10 views
1

Mailgun mail serviceをイオンアプリで設定しようとしています。ここでは、コードです: コントローラー:Ionic http CORS同じ原点が許可されていません

$http({ 
         "method": "POST", 
         "url": "https://api.mailgun.net/v3/" + mailgunUrl + "/messages", 
         //"crossDomain": "true", 
         "headers": { 
          "Access-Control-Allow-Origin": "*",//"http://localhost:8100", 
          "Access-Control-Allow-Headers": "content-type, accept", 
          //"Access-Control-Allow-Credentials": "true", 
          "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE", 
          "Content-Type": "application/x-www-form-urlencoded", 
          'Authorization' : 'Basic '+ mailgunApiKey 
          //"Authorization": "Basic " + mailgunApiKey//$base64.encode('api:key-'+mailgunApiKey) 
         }, 
         data: "from=" + "[email protected]" + "&to=" + $scope.datapopup.mail + "&subject=" + "Guestlist" + "&text=" 

config.xmlの

<content src="main.html"/> 
    <access origin="*"/> 
    <plugin name="cordova-plugin-whitelist" version="1"/> 
    <plugin name="cordova-plugin-crop" spec="~0.1.0"/> 
    <allow-navigation href="*" /> 
    <allow-intent href="*"/> 
    <allow-intent href="http://*/*"/> 
    <allow-intent href="https://*/*"/> 
    <allow-intent href="tel:*"/> 
    <allow-intent href="sms:*"/> 
    <allow-intent href="mailto:*"/> 
    <allow-intent href="geo:*"/> 

私はstatus '0' errorを受信したログは、CORS(クロスオリジンの要求が)アクセス制御 - 許可で許可されていないことを示しています頭が欠けている(フランス語から翻訳された)

さらにChromeのエラーは'Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.'です。

アンドロイドデバイスからも試しましたが、動作しません。何か案が?

答えて

1

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'"> 

をindex.htmlに、アプリにcordova-plugin-whitelistプラグインを追加するためにこれを追加します。


開発の目的で、Chrome用にCORS pluginを使用できます。


お使いのコントローラがこのようなことができます:

.controller("EmailCtrl", function($scope, $http) { 

    var mailgunUrl = "YOUR_DOMAIN_HERE"; 
    var mailgunApiKey = window.btoa("api:key-YOUR_API_KEY_HERE") 

    $scope.recipient = "[email protected]"; 

    $scope.send = function(recipient, subject, message) { 
     $http(
      { 
       "method": "POST", 
       "url": "https://api.mailgun.net/v3/" + mailgunUrl + "/messages", 
       "headers": { 
        "Content-Type": "application/x-www-form-urlencoded", 
        "Authorization": "Basic " + mailgunApiKey 
       }, 
       data: "from=" + "[email protected]" + "&to=" + recipient + "&subject=" + subject + "&text=" + message 
      } 
     ).then(function(success) { 
      console.log("SUCCESS " + JSON.stringify(success)); 
     }, function(error) { 
      console.log("ERROR " + JSON.stringify(error)); 
     }); 
    } 

}) 
+1

あなたが言ったことを既に試してみました。それは動作しません – ai20

+0

私はあなたが解決策を見つけました:)を参照してください。私は数ヶ月前にMailgunとIonicについてのブログ記事を書いたので、それはうまくいきます。 @NightSkyCode? –

+0

なぜ私の答えの4つのためにhttps://postimg.cc/image/h6yuq3ir5/ downvotes?上記の答えはまだ分かりますが、私の他の答えは理解できません。 NightSkyCodeの最初のコメントは、誰かがジャークであることです。だから私は彼のニックネームで疑問符を付けるのは、彼が誰に言及しているのか分からないからです。私はNightSkyCodeのアカウントを見ることができますhttp://stackoverflow.com/users/1530143/nightskycode is suspended "このアカウントは一時的に停止され、停止は9月1日15:41に終了します。 –

0

答えは非常に簡単です:

あなたが任意のオプションパラメータを使用してはならないイオンからアンドロイドを実行すると: イオン実行アンドロイド

関連する問題