const { user } = require('./config');
const axios = require('axios');
const Querystring = require('querystring');
let body = Querystring['stringify']({
email: 'MY [email protected]',
password: 'pass'
})
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios['post']('https://minecraftservers.org/login', body, config)
['then'](response => console.log(response))
Im trying to login through a website it doesn't have an api the headers are correct if you're wandering how i knew this, i used chrome dev tools like reverse engineer
content-type: application/x-www-form-urlencoded
that's the header they used when i tried to login to the site
this is what i get when i logged in through the site and not the code, it works there.
I had to figure out this problem: how to send urlencoded data using Axios? The first thing we need to do is to install the qs module. It’s a cool querystring parsing and stringifying library with some added security: Then we need to import the qs module along with the Axios import, of course: Next, the Axios code.
An API request can be sent in a variety of ways. We can use a command-line tool like cURL, the browser's native Fetch API, or a package like Axios to accomplish this. Sending HTTP requests to your API with Axios is a fantastic tool.
Axios can make a GET request to “get” data from a server. The axios.get () method is used to make an HTTP get request. There are two parameters that must be passed to the get () method.
In short, we need to use the full form for the Axios request. Not axios.post () but axios (). Inside there, we use the stringify () method provided by qs and we wrap the data into it. We then set the content-type header:
You can use URLSearchParams
const params = new URLSearchParams();
params.append('firstName', 'paul');
params.append('lastName', 'fred');
axios.post('/user', params);
It avoids adding another library.
I guess systax is your problem. Do you have any difficulties other than the syntax?
const { user } = require('./config');
const axios = require('axios');
const Querystring = require('querystring');
let body = Querystring['stringify']({
email: 'MY [email protected]',
password: 'pass'
})
const config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios.post('https://minecraftservers.org/login', body, config)
.then(response => console.log(response))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With