SAPUI5 the built-in Ajax class library, ignoring the HTTP headers when submitting a POST request. The GET request does not have this problem.
The following code cannot commit HTTP Headers
sURL = Getsmpurl () + "/odata/applications/latest/com.sap.flight.kapsel/connections";
$.ajax ({
type: "POST",
Cache:false,
url:surl,
data:payload,
beforesend:function (Request) { C6/>request.setrequestheader (' Content-type ', "application/xml");
},
success:function (data, ajaxoptions, XHR) {
alert ("Passed register")
,
error:function (XHR, ajaxoptions, thrownerror) {
alert ("Shit") );
},
xhrfields: {
withcredentials:true,
}
});
The following code can commit HTTP Headers
Write code here
sURL = Getsmpurl () + "/odata/applications/latest/com.sap.flight.kapsel";
$.ajax ({
Headers: {
' Authorization ': "Basic" + Btoa (GetUserName () + ":" + GetPassword ())
},
Type: "GET",
Cache:false,
Url:surl,
DataType: ' xml ',
Beforesend:function (Request) {
},
success:function (data, ajaxoptions, XHR) {
alert ("Passed authentication");
},
error:function ( XHR, Ajaxoptions, thrownerror) {
alert ("shit");
},
xhrfields: {
withcredentials:true,
}
} );
"'