微信小程序连接本地接口
小程序请求本地的后台服务接口:
wx.request({ // 请求地址 url: http://localhost:3000/search?keywords=海阔天空, // 请求方式 method: "get", dataType: json, // GET-header header: { Content-Type: application/json }, // 传参 data: {}, // 方法 success: function (data) { } })
请求很简单,却报了如下错误:
仔细查看API发现
wx.request 请求必须使用HTTPS,并且URL中不能带有端口号
解决办法,
这样就可以请求成功了