美文网首页
微信post 请求

微信post 请求

作者: 一蓑烟雨_龙哥 | 来源:发表于2020-11-20 17:10 被阅读0次
image.png
    wx.login({
      success(res){
        console.log(res)
        var code=res.code;
        wx.request({
          url: 'http://192.168.1.6:8080/wxLogin',
          method :'POST',
          data:{
            code: code
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success :function (res) {
           console.log("-----success-----")
           console.log(res)
            wx.showToast({
              title: res.data.code+"",
            })
           
          },
          fail : function(error){
            console.log("-----fail-----")
            console.log(error)
          }
        })

      },
    })

微信post表单提交,应该添加下面内容

     header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },

@RestController
public class WXLoginController {

    @PostMapping("/wxLogin")
    public ResultData<String> wxLogin(@RequestParam(name = "code") String code){
        System.out.println("wxLogin---code : "+code);
        ResultData data=new ResultData();
        data.setCode(33);
        return data;
    }
    @GetMapping("/hello")
    public ResultData<String> Hello(){

        ResultData data=new ResultData();
        data.setCode(33);
        return data;
    }
}

相关文章

网友评论

      本文标题:微信post 请求

      本文链接:https://www.haomeiwen.com/subject/zgxjiktx.html