SAPUI5内置的AJAX类库对POST请求的处理不提交HTTP HEADERS

    xiaoxiao2025-03-15  13

    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, } });

    “`

    转载请注明原文地址: https://ju.6miu.com/read-1297042.html
    最新回复(0)