0

How to send data in header using websocket?

I'd like to send an apikey in header but not in url.

8th Oct 2017, 12:33 PM
darco
darco - avatar
1 Odpowiedź
+ 2
Here an example, using setRequestHeader to send headers keys var xhr = new XMLHttpRequest(); xhr.open("POST", "ws://api.abc.com/users", true); xhr.setRequestHeader("Abc-Application-Id", "application id"); xhr.setRequestHeader("Abc-ApiKey", "the apikey"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { var result = JSON.parse(xhr.responseText); if (result.object) { alert("Received api object: " + result.object); } } } var data = JSON.stringify({ data: "user data" }); xhr.send(data);
8th Oct 2017, 12:59 PM
Calviղ
Calviղ - avatar