2016-08-02 2 views
1

ionic app에서 Mailgun mail service을 설정하려고합니다. 여기 코드는 다음과 같습니다 컨트롤러 :이오니아 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 (크로스 원산지 요청)에 허용되지 않는 것을 보여 액세스 제어 - 허용받을 머리글이 누락되었습니다 (프랑스어 번역).

크롬의 또 다른 오류는 '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에 대한 downvotes https://postimg.cc/image/h6yuq3ir5/? 위의 대답은 여전히 ​​이해할 수 있지만 다른 대답은 이해할 수 없습니다. NightSkyCode의 첫 번째 의견은 누군가가 멍청이라는 것입니다. 그래서 그가 누구를 언급하고 있는지 명확하지 않아서 닉네임으로 물음표를 넣었습니다. 엉덩이에 NightSkyCode 계정이 표시됩니다. http://stackoverflow.com/users/1530143/nightskycode is suspended "이 계정은 일시적으로 종료되며 일시 중지 기간은 9 월 1 일 15시 41 분에 종료됩니다." –

0

대답은 매우 간단합니다 : 이온 실행 안드로이드 : 당신이 이온 성에서 안드로이드를 실행할 때

당신은 어떤 선택적 매개 변수를 사용하지 말아야합니다

관련 문제