2
I need to make an ajax call by passing in Header the following information: Content-Type:application/json Cookie:authToken=valueXPTO (This information above I got from Postman)
I need to do the same thing only I saw Ajax, and there’s no way I’m doing it. Someone can help me?
Follow the code below:
function LogoutToken(){
debugger;
var urlApi = 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 the following error: Internal Server Error
In C# I execute the following way and in the right way:
RestRequest request = new RestRequest(Method.POST);
request.AddCookie("authToken", token);
Which error does it present? As a POST I think the 'date' was missing (content of the request).
– Anderson Souza
@Andersonsouza he from Internal Server Error. But I have no data to pass. This API is only for killing the token session. For it I need to pass only the session token as example of the Postman image.
– Evandro Sousa
In Postman it generates the Header like this: Content-Type:application/json Cookie:authToken=webXPTO123
– Evandro Sousa
which value of urlApi?
– Anderson Souza
https://chp.tbe.taleo.net/chp04/ats/api/v1/logout
– Evandro Sousa
Post a photo of the Headers(16) tab of Postman
– Anderson Souza
Or better still in Postman has an option called "Code" selects the Javascript option -> Jquery AJAX, then compares with your request.
– Anderson Souza
Thanks, I didn’t really know that part of the Postman code, but even picking up there isn’t going. When I am debugging, it arrives at the cookie line and gives the following error: Refused to set unsafe header "cookie": xhr.setRequestHeader("cookie", "authToken=" + Token);
– Evandro Sousa
@Andersonsouza had another hidden error, this one:Failed to load https://chp.tbe.taleo.net/chp04/ats/api/v1/logout: Response to preflight doesn’t request pass access control check: The value of the 'Access-Control-Allow-Origin' header in the Response must not be the wildcard '*' when the request’s credentials mode is 'include'. Origin 'null' is therefore not allowed access. The credentials mode of requests initiated by the Xmlhttprequest is Controlled by the withCredentials attribute.
– Evandro Sousa
The header you requested: access-control-allow-headers x-requested-with, Content-Type, origin, Authorization, Accept, client-security-token access-control-allow-methods POST, GET, OPTIONS, DELETE, PUT access-control-allow-origin * access-control-max-age 1000 cache-control no-cache, no-store, max-age=0 Connection Keep-Alive content-encoding gzip content-language en-BR content-type application/json;charset=UTF-8 date Fri, 17 Nov 2017 16:17:35 GMT expires Thu, 01 Jan 1970 00:00:00 GMT .. Continues
– Evandro Sousa
Keep-Alive timeout=5, max=100 pragma no-cache server Apache transfer-encoding chunked Vary Accept-Encoding,
– Evandro Sousa
Man erases the comment with the security token
– Anderson Souza
A relaxes, this token is dev and it changes every session. Every time I order here I delete by Postman.
– Evandro Sousa
Blz.. this error: :Failed to load chp.tbe.Taleo.net/chp04/Ats/api/v1/logout , is Cors but this is from the served side. a search how to enable Cors ai in api
– Anderson Souza
Take a look at this one: https://stackoverflow.com/questions/33143776/ajax-request-refused-to-set-unsafe-header I think you’ll answer
– Edison Harada