SAPUI5内置的AJAX类库,在提交POST请求的时候,忽略了http headers。GET请求没有这个问题。
下面的代码不能提交HTTP Headers
sUrl = getSMPURL() + "/odata/applications/latest/com.sap.flight.kapsel/Connections"; $.ajax({ type : "POST", cache : false, url: sUrl, data: payload, beforeSend : function(request) { request.setRequestHeader('Content-Type', "application/xml"); }, success : function(data, ajaxOptions, xhr) { alert("passed register"); }, error : function(xhr, ajaxOptions, thrownError) { alert("shit"); }, xhrFields : { withCredentials : true, } }); 下面的代码可以提交HTTP Headers这里写代码片 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, } });“`