我如何将我的 curl 命令转换为 angularjs http 请求

how can i convert my curl command to angularjs http request

需要将下面的curl命令转换成angularhttp请求。 命令看起来类似于下面的命令。

" curl -X POST --data 'username=myusername&password=mypassword' -i https://myurl.com/j_spring_security_check "

在我想使用的 https 中,GET 或 POST。任何人都可以帮忙吗。

它可能是一个具有 postMethod 方法的服务,该方法采用两个参数用户名和密码,就像这样:

angular.factory('myService', ['$http', function($http){
    function postMethod(username, password){
        var request = {
            method:'POST',
            url: 'https://myurl.com/j_spring_security_check ',
            data: {
                username:username,
                password:password
            }
        }
        return $http(request);
    }

    return {
        postMethod:postMethod
    }
]);

然后您就可以使用您的服务了:

angular.module('myapp').controller('MainCtrl', ['myService', function(myService){
    myService.postMethod('foo', 'bar').then(function(response){
        // Do a UI change ?
    });
}]);