我使用Axios来执行如下的HTTP post:
import axios from 'axios'
params = {'HTTP_CONTENT_LANGUAGE': self.language}
headers = {'header1': value}
axios.post(url, params, headers)
这对吗?或者我应该这样做:
axios.post(url, params: params, headers: headers)
我使用Axios来执行如下的HTTP post:
import axios from 'axios'
params = {'HTTP_CONTENT_LANGUAGE': self.language}
headers = {'header1': value}
axios.post(url, params, headers)
这对吗?或者我应该这样做:
axios.post(url, params: params, headers: headers)
当前回答
你可以传递一个配置对象给axios,比如:
axios({
method: 'post',
url: '....',
params: {'HTTP_CONTENT_LANGUAGE': self.language},
headers: {'header1': value}
})
其他回答
正确的方法是:- axios。Post ('url', {"body":data}, { 标题:{ “内容类型”:“application / json” } } )
你可以初始化一个默认头axios.defaults.headers
axios.defaults.headers = {
'Content-Type': 'application/json',
Authorization: 'myspecialpassword'
}
axios.post('https://myapi.com', { data: "hello world" })
.then(response => {
console.log('Response', response.data)
})
.catch(e => {
console.log('Error: ', e.response.data)
})
我在申请职位时遇到了这个问题。我在axios header中做了如下更改。它工作得很好。
axios.post('http://localhost/M-Experience/resources/GETrends.php',
{
firstName: this.name
},
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
如果你想用参数和头来做一个get请求。
这是瓦尔 paramName1: paramValue1 paramName2: paramValue2 …… 瓦尔希德斯 headerName1: headerValue1 headerName2: headerValue2 …… Axios。输入url然后(res = >—— console.log (res.data.representation); 新程序);
axios。Post ('url', {"body":data}, { 标题:{ “内容类型”:“application / json” } } )