2016-11-17 5 views
0

私は、角度jsの初心者です。私はangularjsで$ httpサービスを試しています。私はWebサービスにアクセスしています。 ubuntuでcurl文を使用した場合に期待される応答を返しますが、curlのパラメータが$ http.post()パラメータにマップされている場合は成功しません。 curlとangularjsの両方のページについて私のコードを見てください。私の間違いを指摘し、問題を解決するのを手伝ってください。

curl --data "[email protected]" HTTP://dummy.dummyplane.com/dummyservices/UserExists 

結果:

{"Data":"123456","Success":true,"Exception":null} 

Angularjsコード

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script> 
</head> 

<body ng-app="myapp"> 
<div ng-controller="registerController"> 
    <button ng-click='Register()' style='margin-top:15px'>Register</button> 
</div> 
<script type="text/javascript"> 

var app = angular.module('myapp', []); 
app.controller('registerController', function($scope, $http) { 

$scope.Register = function() { 
    $http({ 
     url:'http://tethys.dev.riekerinc.com/totalsolutions/UserExists/', 
     method:'POST', 
     data:{"email":"[email protected]"}, 
     headers:{'Content-Type':'application/x-www-form-urlencoded'} 
    }).success(function(data){ 
     //console.log(data) 
     alert("Success"); 
    }); 

}; 
    }); 

    </script> 

</body> 
</html> 

答えて

1

あなたは正しい値にコンテンツタイプを設定していますが、デフォルトとは異なるシリアライザを使用するように角度を教えていません1つで、JSON形式で送信します。

使用$httpParamSerializerJQLike、または単に文字列としてデータを送信します。

data: '[email protected]' 
関連する問題