post request with XMLHttpRequest javascript

2019-08-16 19:23发布

I tried to send post request but always get: 403 and Authentication requires

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const http = new XMLHttpRequest();
const url = "https://mywebsite.com/api/comment";
const params = 'comment=test';
http.open("POST", url, false, login, password);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(params)

If I try to log in I get: {"status":"nok","message":"Not JSON"}

const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const http = new XMLHttpRequest();
const url = "https://mywebsite.com/api/login";
const params = 'login=admin&password=admin'
http.open("POST", url, false);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.send(params);

I wolud like to change some data by request before I log in manually.

0条回答
登录 后发表回答