ngResource:Angularjs-发送带有标题和请求正文的post请求

ngResource:Angularjs-发送带有标题和请求正文的post请求,angularjs,post,http-headers,httprequest,ngresource,Angularjs,Post,Http Headers,Httprequest,Ngresource,我正在尝试发送一个带有标题和请求正文的post请求。到目前为止,我已经达到了这一点: createJob: function(jobName, jobAddress, jobContact, jobComments) { var payload = { name: jobName, address: jobAddress,

我正在尝试发送一个带有标题和请求正文的post请求。到目前为止,我已经达到了这一点:

createJob: function(jobName, jobAddress, jobContact, jobComments) {
                    var payload = {
                        name: jobName,
                        address: jobAddress,
                        contact: jobContact,
                        comments: jobComments
                    };
                    console.log(payload);
                    return $resource(route, {}, {
                       save: {
                           method: 'POST',
                           header: {'Content-Type': 'application/json'},
                           transformRequest: function(data){
                               console.log('Data in transform request is');
                               console.log(data);
                               return data; // this will go in the body request
                           }
                       }
                    });
                }
我不知道在这种情况下,有效载荷应该放在哪里,有什么帮助吗?此外,在打电话时,我目前正在尝试以下操作:

createJob(this.jobName, this.jobAddress, this.jobContact, this.jobComments).
                    save().$promise.
                    then(function (response) {
                        console.log('Create job response is');
                        console.log(response);
                    }).
                    catch(function (error) {
                        console.log('Create job error is');
                        console.log(error);
                    });

任何帮助都将不胜感激

我为所有感兴趣的人提供了一个解决方案:

createJob: function(jobName, jobAddress, jobContact, jobComments) {
            var payload = {
                name: jobName,
                address: jobAddress,
                contact: jobContact,
                comments: jobComments
            };
            console.log(payload);
            return $resource(route, {}, {
                save: {
                    method: 'POST',
                    transformRequest: function(data){
                        console.log('Data in transform request is');
                        console.log(data);
                        return angular.toJson(data); // this will go in the body request
                    }
                }
            }).save({}, payload);
        }

createJob(this.jobName, this.jobAddress, this.jobContact, this.jobComments).$promise.
            then(function (response) {
                console.log('Create job response is');
                console.log(response);
                //Refresh the page so newly created job can be seen
                window.location.reload();
            }).
            catch(function (error) {
                console.log('Create job error is');
                console.log(error);
            });