I tried to make a SOAP call to a web service through AJAX Proxy (in a visualforce page) but I can't configure the basic authentication in the header. Does anyone know how to do it? Here is my code:

<apex:page >

<script src="../../soap/ajax/22.0/connection.js" type="text/javascript"></script>
<script type="text/javascript"> 

    function makeBaseAuth(user, pswd) { 
    var token = user + ':' + pswd;
    var hash = "";
    if (btoa) {
        hash = btoa(token);
    return "Basic " + hash;

function testAjaxProxy() {
    //var __sfdcSessionId = '{!GETSESSIONID()}';
    var envelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\"> <soapenv:Header/> <soapenv:Body> <urn:Z_BN_MAESTRO_MATERIAL> <T_SALIDA> </T_SALIDA> </urn:Z_BN_MAESTRO_MATERIAL> </soapenv:Body> </soapenv:Envelope>"; //request envelope, empty for this example
    var USERNAME = '';
    var PASSWORD = '';
        url : "",
        requestHeaders: {"Content-Type":"text/xml",
                         "Authorization": makeBaseAuth(USERNAME,PASSWORD)
        requestData: envelope,
        method: "POST",
        onSuccess : function(response) {
        onFailure : function(response) {
            alert("Failed" + response)

<apex:pageBlock >

    <p><button onClick="testAjaxProxy()">Test AJAX Proxy</button></p>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.