Run Ajax by passing credential information to the Header

1

I need to make an ajax call by passing in the Header the following information: Content-Type: application / json Cookie: authToken = valueXPTO (This information above I got from Postman)

IneedtodothesamethingexceptIsawAjax,andnowayamIgettingit.Cananyonehelpme?

Followthecodebelow:

functionLogoutToken(){debugger;varurlApi=urlBase+"logout";

            $.ajax({
                type: "POST",
                dataType: 'json',
                url: urlApi,
                crossDomain: true,
                async: false,
                contentType: "application/json; charset=utf-8",
                beforeSend: function(xhr) {
                    xhr.setRequestHeader('Cookie', 'authToken=' + Token);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(textStatus);
                    alert('Falha na consulta de valores específicos, erro:' + textStatus);
                },
                success: function (msg) {
                    var xyx = msg;
                }
            });
        }

When I run this way it gives the following error: Internal Server Error

In C # I execute as follows:

        RestRequest request = new RestRequest(Method.POST);
        request.AddCookie("authToken", token);
    
asked by anonymous 17.11.2017 / 01:20

1 answer

0

Try the Header this way inside the ajax configuration object

"headers":{
    "Cookie":"authToken=valorXPTO
}

Source: JQuery Documentation

    
17.11.2017 / 02:03