To use this function you just need to create two NameValueCollections holding your parameters and request headers. Show activity on this post. You can also pass value directly via URL. If you want to call method public static void calling(string name){....}
Axios' post() function supports a data parameter that becomes the HTTP request body. On the other hand, axios. get() does not support this parameter.
POST JSON with AxiosIf you send a serialized JSON object as data, however, Axios considers it as “application/x-www-form-urlencoded” (form-encoded request body). You must manually set the header using the “headers” config option if the intended content type is JSON.
axios.get
accepts a request config as the second parameter (not query string params).
You can use the params
config option to set query string params as follows:
axios.get('/api', {
params: {
foo: 'bar'
}
});
On client:
axios.get('/api', {
params: {
foo: 'bar'
}
});
On server:
function get(req, res, next) {
let param = req.query.foo
.....
}
This works fine for me. When it is post request nested data object isn't needed but in get requests, in order to send data, you need it.
axios.get('/api', {
data: {
foo: 'bar'
}
}
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