Xin chào !
Mình gặp vấn đề khi truyền data
lên server bằng axios, mình xác định được lỗi là do Content-Type:application/json
ở phần header (mã lỗi 400 và 415).
Mình test bằng POSTMAN server vẫn hoạt động bình thương ( status code 200OK)
Đây là phần header của request
Đây là phần body
Đây là code Axios của mình
axios({
method: 'GET',
url: 'https://localhost:44376/api/Fee',
headers: {
'Content-Type': 'application/json'
},
data: {
from_district_id: 1454,
service_id: 53320,
to_district_id: 1452,
to_ward_code: 21012,
height: 50,
length: 20,
weight: 200,
width: 20,
insurance_fee: 10000
}
}).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
Bị lỗi
xhr.js:177 GET https://localhost:44376/api/Fee 400
createError.js:16 Uncaught (in promise) Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:62)
JSON.stringify data
let data= JSON.stringify({
from_district_id: 1454,
service_id: 53320,
to_district_id: 1452,
to_ward_code: 21012,
height: 50,
length: 20,
weight: 200,
width: 20,
insurance_fee: 10000
});
axios.get('https://localhost:44376/api/Fee', data,
{
headers : {
'Content-Type': 'application/json'
}
}
).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
};
Bị lỗi như này :
TypeError: Cannot use 'in' operator to search for 'validateStatus' in {"from_district_id":1454,"service_id":53320,"to_district_id":1452,"to_ward_code":21012,"height":50,"length":20,"weight":200,"width":20,"insurance_fee":10000}
Cảm ơn các bạn!
#lep