Last active
November 17, 2017 16:54
-
-
Save hex-ci/43dacac0c4183df821eada04064b1a62 to your computer and use it in GitHub Desktop.
Axios with QueryString form data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios' | |
import qs from 'qs' | |
const axiosInstance = axios.create({ | |
transformRequest: [function(data) { | |
return qs.stringify(data); | |
}], | |
headers:{ | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
}) | |
// Send a POST request | |
axiosInstance({ | |
method: 'post', | |
url: '/demo/12345', | |
data: { | |
key1: 'value1', | |
key2: 'value2' | |
} | |
}).then(function(response) { | |
console.log(response) | |
}) | |
.catch(function(error) { | |
console.log(error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment