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:[email protected], Phone:9876554433,…}
1. Country: "UK"
2. Email: "[email protected]"
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') 用戶( '123') 2014-11-21T15:21:52Z RAJESH 窿 [email protected] 英國 RG4 6SA
JSON格式:
{ d: { __metadata: { ID: 「主機:端口/ SAP/OPU /的OData/SAP /用戶/用戶( '123')」 URI: 「主機:端口/ SAP/OPU /的OData/SAP /用戶/用戶( '123')」 類型: 「USERS.User」 } - 用戶名: 「123」 姓: 「拉傑什」 名字: 「窿」 電子郵件: 「[email protected]」 電話: 「123456789」 國家:「英國」 郵編:「RG4 6SA」 } - }
您不需要添加內容類型標題,angular會爲您排序。 post方法沒有太多錯誤,它可能是你想要查看的服務。 – BenCr 2014-11-21 11:56:30
嗨,本,我已經嘗試了與你之前建議的一樣,但沒有運氣。而且我可以確認我的服務對於來自SAP網關客戶端和Chrome REST客戶端的所有CRUDQ操作都絕對正常。但我懷疑格式它試圖發佈不匹配....我看到的錯誤是XML格式錯誤。 – 2014-11-21 13:30:02
默認情況下Angularjs會發送JSON而不是XML。您的服務是否期待XML?我不知道如何製作角色發送XML,或者即使可以。 – BenCr 2014-11-21 15:36:18