In the WeChat applet, POST, FormData format transfer parameters

status quo

The POST submission method used by the backend interface uses FormData to pass parameters, but there is no FormData function in the WeChat applet. If the backend changes the JSON format, the change will be large, so there is no way to change it to JSON, so we can only start from the interface.
I searched a lot on the Internet for passing parameters in FormdData format. There are those who want to import this js file and those who need to splice strings, but the parameters received in the background are empty, so I simulated calling the interface through the web and set WeChat according to the request header. Request header settings in the request.

the code

code behind

@PostMapping(value = "/methodurl")
@ResponseBody
methodName(Integer page, Integer size,String state,HttpServletRequest request) {
    
    }

web request

Request Headers:
	Accept: application/json, text/javascript, */*; q=0.01
	Accept-Encoding: gzip, deflate, br
	Accept-Language: zh-CN,zh;q=0.9
	Connection: keep-alive
	Content-Length: 22
	Content-Type: application/x-www-form-urlencoded; charset=UTF-8
	Cookie: ****
	Host: localhost:8080
	Origin: http://localhost:8080
	Referer: http://localhost:8080/methodurl
	sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
	sec-ch-ua-mobile: ?0
	sec-ch-ua-platform: "Windows"
	Sec-Fetch-Dest: empty
	Sec-Fetch-Mode: cors
	Sec-Fetch-Site: same-origin
	User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
	X-Requested-With: XMLHttpReques

Payload:
	page=1&size=10&state=0

WeChat applet (text, you can jump directly here)

Just write it like this, you don’t need to set anything else,

data: 'page=1&size=10&state=0',
header: {
  'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
method: "POST",

Guess you like

Origin blog.csdn.net/qq_16607641/article/details/128715565