قضيت يومًا كاملاً تقريبًا في محاولة لمعرفة سبب إرسال Axios لبياناتي بتنسيق خاطئ حتى وجدت هذا http://stackoverflow.com/questions/31756756/axios-http-client-how-to-construct-http-post- عنوان url مع شكل المعلمات. الإصلاح هو استخدام وحدة سلسلة الاستعلام.
axios.post(
'/api/v1/auth/login',
querystring.stringify({ // <-- this is what fixed it. JSON.stringify didn't help here
user_id: this.state.user_id,
password: this.state.password,
_csrf: result.data.csrfToken
}),
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((res) => {
if (res.data && res.data) {
console.log('here')
}
})
.catch((err) => {
console.log(err);
});
ومع ذلك ، أشعر أن أكسيوس يجب أن تهتم بهذا الأمر.
توجد بالفعل تعليمات في الملف التمهيدي ، لذلك كان من السهل جدًا العثور على الإجابة:
https://github.com/mzabriskie/axios#using -applicationx-www-form-urlencoded-format
ما إذا كان يجب على Axios الاهتمام بهذا الأمر تلقائيًا أم لا ، ليس سؤالًا يجب الإجابة عليه ، ولكن التركيز الرئيسي للمكتبة هو إرسال JSON ، لذلك أعتقد أنه يتم تحسين حالة الاستخدام هذه.
أوه ، شكرا لك على هذا الرابط. لم أره من قبل.
يمكنك استخدام params
لتحديد سلاسل الاستعلام.
// `params` are the URL parameters to be sent with the request
// Must be a plain object or a URLSearchParams object
params: {
ID: 12345
},
التعليق الأكثر فائدة
يمكنك استخدام
params
لتحديد سلاسل الاستعلام.