SAPUI5 the built-in AJAX class library handles post requests without committing HTTP HEADERS

Source: Internet
Author: User
Tags commit

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

"'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.