Home > Database > Mysql Tutorial > body text

How do I send query parameters with Axios in a POST request?

Mary-Kate Olsen
Release: 2024-11-01 10:50:02
Original
423 people have browsed it

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>
Copy after login

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&amp;firstname=myFirstName
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!