I am new to AngularJS, I am from SAP background and as part of my PoC I built my REST services using SAP NW Gateway,I am facing an issue to POST data from Angularjs to my REST services.Please find the below detailed error log
***1. Remote Address:
10.xxx.xx.xx:8000
2. Request URL:
//host:port/sap/opu/odata/sap/USERS/Users
3. Request Method:
POST
4. Status Code:
400 Bad Request
5. Request Headersview source
1. Accept:
application/json, text/plain, */*
2. Accept-Encoding:
gzip,deflate
3. Accept-Language:
en,te;q=0.8
4. Authorization:
Basic a2VsYW1yOmoyZDEwMA==
5. Connection:
keep-alive
6. Content-Length:
146
7. Content-Type:
application/json;charset=UTF-8
8. Cookie:
sap-usercontext=sap-client=100; SAP_SESSIONID_J2D_100=R_60WyUyNG2nV1MbhC9QAcKPzyBwwxHkmwsAUFaDBqQ%3d
9. Host:
abcdefgh:8000
10. Origin:
file://
11. User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
12. X-CSRF-Token:
_jXDnt2Cdpplpj5zvK3iPA==
6. Request Payloadview source
{UserID:555, FirstName:rajesh555, LastName:kelam555, Email:rajesh555@gmail.com, Phone:9876554433,…}
1. Country: "UK"
2. Email: "rajesh555@gmail.com"
3. FirstName: "rajesh555"
4. LastName: "kelam555"
5. Phone: 9876554433
6. Postcode: "TW18 4BL"
7. UserID: 555
7. Response Headersview source
1. content-length:
535
2. content-type:
application/json
3. dataserviceversion:
1.0****
Angular Code for Post :
$scope.addRow = function () {
var config = {};
var pushdata = {'UserID':$scope.UserID, 'FirstName':$scope.FirstName, 'LastName':$scope.LastName, 'Email':$scope.Email, 'Phone':$scope.Phone, 'Country':$scope.Country, 'Postcode':$scope.Postcode};
// Sending Notification to User
growl.addSuccessMessage("User Created", config);
/* $http.post(url,pushdata, {'Content-Type':'application/json'}).success(function(pushdata) {
$scope.resultSet = pushdata.d.results;
alret("Data Posted");
}) */
$http.post(url,pushdata, {headers:{'Content-Type':'application/json'}}).success(function(data){alert(data);});
$scope.resultSet.push(pushdata);
$scope.createMessage();
$scope.UserID='';
$scope.FirstName='';
$scope.LastName='';
$scope.Email='';
$scope.Phone='';
$scope.Country='';
};
it would be great if some one help me to sort.
*Note: I am a kid in AngularJS...please ignore me and feel free to thought me.
I request to suggest the best URl/Site to learn Angularjs in a better and consistent way.
I thought, if I share the format(XML/JSON) of payload expecting for the POST to perform by my SAP Gateway service which will helps me to quickly resolve this.Below are the formats of XML/JSON works for POST.
XML格式:
主机:端口/ SAP / OPU /的OData / SAP /用户/用户(' 123&#39)
用户(' 123&#39)
2014-11-21T15:21:52Z
123
拉杰什
窿
RAJESHKUMAR.KELAM@ABG.CO.UK
123456789
联合王国
RG4 6SA
JSON格式:
{
d:
{
__metadata:
{
id:" host:port / sap / opu / odata / sap / USERS / Users(' 123')"
uri:" host:port / sap / opu / odata / sap / USERS / Users(' 123')"
类型:" USERS.User"
}
-
用户ID:" 123"
FirstName:" RAJESH"
姓氏:" KELAM"
电子邮件:" RAJESHKUMAR.KELAM@ABG.CO.UK"
电话:" 123456789"
国家:"英国"
邮编:" RG4 6SA"
}
-
}
答案 0 :(得分:0)
您确定发布的网址是否需要发布此数据?您可以使用POSTMAN扩展程序(在谷歌浏览器中)并测试您的服务是否已准备好从http.post接收任何数据
答案 1 :(得分:0)
最后,我能够解决我的问题,这是关于格式化传递给REST服务的数据..
下面是代码的工作原理
$ scope.addRow = function(){
var StrUId = ($scope.UserID).toString();
var StrPh = ($scope.Phone).toString();
var pushdata = {"UserID":StrUId, "FirstName":$scope.FirstName, "LastName":$scope.LastName, "Email":$scope.Email, "Phone":StrPh, "Country":$scope.Country, "Postcode":$scope.Postcode};
// Posting data
$http({
method: "post",
url:url,
data:pushdata,
headers: {
"X-CSRF-Token": "0XGo8HzpzrhaZxxX83QH9g==",
},
dataType : "json",
async: false,
contentType: 'application/json',
success: function(data){
alert(data);
}
});
感谢您给予的支持 拉杰什