Answer the question
In order to leave comments, you need to log in
How to send a POST request to the form of someone else's site and get a response?
Task: It is necessary to send a post request to someone else's site with a specific id number, so that I get a response with an answer whether this id is suitable.
I did it in 2 ways.
I tried to do it via fetch(). At the beginning I had a header - content-type: application/json. But I had an error and required Access-Control-Allow-Origin.
But now I am getting the following error:
The provided value is not of type "(sequence<sequence<ByteString>> or record<ByteString, ByteString>)".
let post_id = "<?php echo $_POST['id'] ?>";
let url = "https:";
const data = {"id" : post_id};
console.log("data id: " + data);
fetch(url, {
method: 'POST',
headers: "Access-Control-Allow-Origin",
body: JSON.stringify(data)
}).then((value =>
console.log(value)
));
console.log("post_id: " + post_id);
console.log("url: " + url);
let url = "https:";
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("authorization", "Token xxxxxx");
xhr.setRequestHeader("Access-Control-Allow-Origin", "1111");
xhr.send();
xhr.responseText;
Answer the question
In order to leave comments, you need to log in
For security reasons, requests from foreign domains are not accepted, so you need to allow them to be accepted.
header("Access-Control-Allow-Origin: http://example.com");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question