I am using Axios within the Nodejs environment to make a request to get data, but when i'm using POST request with a content type 'application/x-www-form-unlencoded' i receive a response with error 403. Where is the problem in this HTTP request?, because with other tools it works for me. Here is an example of what i'm doing:
const axios = require('axios');
(async () => {
try {
let res = await axios({
method: 'post',
baseURL: 'https://www3.animeflv.net',
url: '/api/animes/search',
data: 'value=tokyo',
headers: { 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64)',
'Content-Type': 'application/x-www-form-urlencoded'}
})
console.log(`statusCode: ${res.status}`);
console.log(res.data.data);
} catch (error) {
console.error(error.response);
}
})();
When i execute this, the response of the API is this:
Also when i make the POST request with curl command in Linux, the response is successful, as shown below:
I think that your code is working fine, because if you look at the "data" part of the response ( console.error(error.response.data);
) you get, you can see that you receive a "Check your browser" HTML webpage, that the browser should have rendered.
You get the same response if you are using an API Client like Insomnia ( Screenshot of the request in Insomnia ).
Maybe you have to use another api, or spawn a child_process that executes curl to make the request, just like you did on the command line.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.