1. 程式人生 > 其它 >uniapp請求,使用x-www-form-urlencoded報錯

uniapp請求,使用x-www-form-urlencoded報錯

技術標籤:筆記javascriptuni-app

uni.request({
	url: '',//被我刪了介面
	header: { 
		'content-type': 'application/x-www-form-urlencoded'
	},
	method:'POST', //請求方式
	data:that.loginData,
	success: function(res) {
		console.log(res)
	}
})

在這裡插入圖片描述

一直報錯500。
因為介面需要使用x-www-form-urlencoded,查了好久,才發現是這個header的問題。
header要放在前面,修改一下位置。

uni.request({					
	header: { 'content-type': 'application/x-www-form-urlencoded'},
	url: '',//被我刪了介面
	method:'POST', //請求方式
	data:that.loginData,
	success: function(res) {
		console.log(res)
	}
})

在這裡插入圖片描述
200成功

如果本文幫助到你或對你有啟發,點個贊再走唄