I'm trying to make https requests to the server using axios. Most of the tutorials regarding axios specify how to make http requests. I make the requests whenever users login. Here is my current request:
axios.post('/api/login/authentication', {
email: email,
password: password
})
.then(response => {
this.props.history.push('/MainPage')
})
.catch(error => {
console.log(error)
})
Can anyone help me convert this to an https request?
All URLs have two parts
http://yourdomain.com
/path-to-your-endpoint
In axios
, if you specify just the path
, it will use the domain in the address bar by default.
For example, the code below will make a call to whatever domain is in your address bar and append this path to it. If the domain is http
, your api request will be a http
call and if the domain is https
, the api request will be a https
call. Usually localhost
is http
and you will be making http
calls in localhost
.
axios.post('/api/login/authentication', {
On the other hand, you can pass full URL to axios request and you will be making https
calls by default.
axios.post('https://yourdomain.com/api/login/authentication', {
You can also set baseURL
in axios
axios({
method: 'post',
baseURL: 'https://yourdomain.com/api/',
url: '/login/authentication',
data: {
email: email,
password: password
}
}).then(response => {
this.props.history.push('/MainPage')
})
.catch(error => {
console.log(error)
});
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