Welcome! Log In Create A New Profile


nginScript send POST resquest

February 24, 2018 05:37AM
I tried to send some POST request to remote server (as part of external authentication), but I got message that XMLHttpRequest is undefined (or similar error).
I saw later in this post https://forum.nginx.org/read.php?2,275459,275459#msg-275459 answer that this is not possible.

Can it help if NodeJS is installed, or nginScript it completely independent? (I don't have much experience in any javascript stuff)

This is how my script looks:

function baz(req, res) {
res.headers.foo = 1234;
res.status = 200;
res.contentType = "text/plain; charset=utf-8";
res.contentLength = 22;
res.send("Enginx ");
var response = "resp";

var data = "{\n \"page\": 0,\n \"count\": 1,\n \"order\": 2,\n \"sort\": \"0\",\n \"headers\": {\n \"Access-Control-Allow-Origin\": [\n \"*\"\n ]\n }\n}";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
// console.log(this.responseText);

xhr.open("POST", "https://remote.host/api/login", false);

xhr.setRequestHeader("origin", "https://localhost");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("referer", "https://localhost/");
xhr.setRequestHeader("accept-encoding", "gzip, deflate, br");
xhr.setRequestHeader("accept-language", "sr-RS,sr;q=0.9,en-US;q=0.8,en;q=0.7,hr;q=0.6,bs;q=0.5");
xhr.setRequestHeader("cookie", "securitytoken=eyJraWQiOiJ.......Swnq3xjEvXodQ");


xhr.onreadystatechange = processRequest;

function processRequest(e) {
if (xhr.readyState == 4 && xhr.status == 200) {
response = JSON.parse(xhr.responseText);
// alert(response.ip);

Subject Author Posted

nginScript send POST resquest

matke February 24, 2018 05:37AM

Re: nginScript send POST resquest

Roman Arutyunyan February 26, 2018 06:56AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 95
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready