我使用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。Post ('url', {"body":data}, { 标题:{ “内容类型”:“application / json” } } )
其他回答
如果你想用参数和头来做一个get请求。
这是瓦尔 paramName1: paramValue1 paramName2: paramValue2 …… 瓦尔希德斯 headerName1: headerValue1 headerName2: headerValue2 …… Axios。输入url然后(res = >—— console.log (res.data.representation); 新程序);
你可以初始化一个默认头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。Post ('url', {"body":data}, { 标题:{ “内容类型”:“application / json” } } )
正确的方法是:- axios。Post ('url', {"body":data}, { 标题:{ “内容类型”:“application / json” } } )
这是一个简单的配置头和responseType的例子:
var config = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
responseType: 'blob'
};
axios.post('http://YOUR_URL', this.data, config)
.then((response) => {
console.log(response.data);
});
Content-Type可以是'application/x-www-form-urlencoded'或'application/json' 也可以是'application/json;charset=utf-8'
responseType可以是arraybuffer, blob, document, json, text, stream
在这个例子中,这个。数据就是你想要发送的数据。它可以是一个值或数组。(如果你想发送一个对象,你可能需要序列化它)