Home >Database >Mysql Tutorial >How do I send query parameters with Axios in a POST request?
Query Parameter Posting with Axios
When making a POST request with Axios, you may encounter a scenario where you need to attach query parameters to the URL. This differs from sending data within the request body.
One common issue is when attempting to pass query parameters with Axios in React Native, resulting in a 400 error due to invalid query parameters.
To resolve this, Axios requires you to specify query parameters differently from request data. While the function signature for post is axios.post(url[, data[, config]]), you'll need to pass the query parameters as the third argument within the config object.
To illustrate, consider the following code:
<code class="javascript">.post(`/mails/users/sendVerificationMail`, null, { params: { mail, firstname }}) .then(response => response.status) .catch(err => console.warn(err));</code>
This code will send a POST request with an empty body and the specified query parameters:
POST http://localhost:8000/api/mails/users/sendVerificationMail?mail=lol%40lol.com&firstname=myFirstName
The above is the detailed content of How do I send query parameters with Axios in a POST request?. For more information, please follow other related articles on the PHP Chinese website!