微信小程序POST请求,后台获取不到参数

一开始的请求:

wx.request({
    url: baseUrl + 'tea/exportsg.action',
    data: { email: email, cId: cId },
    method: 'POST',
    success: function (res) {
        
    }, fail: function () {

     }
 })

后台获取到为null的原因,wx.request()中 header  content-type 默认为 application/json,微信小程序官方API

对于POST请求,content-type应该是'content-type': 'application/x-www-form-urlencoded'

修改后的成功请求:

wx.request({
        url: baseUrl + 'tea/exportsg.action',
        data: { email: email, cId: cId },
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded' 
        },
        success: function (res) {
          
        }, fail: function () {

        }
      })

后台获取的源码:

@RequestMapping(value="/exportsg" ,method=RequestMethod.POST)
	public ResponseEntity exportSignRecords(HttpServletRequest request) {
		String email = request.getParameter("email");
		JSONObject rtnInfo = new JSONObject();//返回的json信息
		
        System.out.println(email);
		
		rtnInfo.put("status", "200");
		return ResponseEntity.status(HttpStatus.OK).body(rtnInfo);
	}

 

你可能感兴趣的:(微信小程序/公众号,SSM框架)