微信小程序> 微信小程序使用WebSocket的坑-微信小程序使用缺点-微信小程序的优缺点

微信小程序使用WebSocket的坑-微信小程序使用缺点-微信小程序的优缺点

浏览量:2875 时间: 来源:今天只卖大白菜
微信小程序使用WebSocket的坑1.

http与https协议使用http协议,websocket的url,应该是ws开头,如:ws://abc.cn/websocket/infos使用https协议,websocket的url,应该是wss开头,如:wss://abc.cn/websocket/infos

2.

nginx使用https反向代理tomcatnginx的443端口反向代理tomcat,需要在conf文件的header上面增加以下参数

proxy_http_version1.1;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";3.

顺便贴一下,微信小程序项目的完整的https协议的nginx反向代理配置

server{listen443ssl;server_nameabc.xxx.cn;sslon;ssl_certificatecert/ssl/abc.xxx.cn.pem;ssl_certificate_keycert/ssl/abc.xxx.cn.key;ssl_session_timeout5m;ssl_ciphersECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocolsTLSv1TLSv1.1TLSv1.2;ssl_prefer_server_cipherson;proxy_http_version1.1;proxy_set_headerUpgrade$http_upgrade;proxy_set_headerConnection"upgrade";proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Proto$scheme;#微信小程序推送配置校验文件路径location/123.txt{proxy_passhttps://127.0.0.1:8443/static/123.txt;}location/{includeuwsgi_params;proxy_passhttps://127.0.0.1:8443;}}在开发工具调试websocket没有问题,使用真机测试一直pending的问题查了半天,才发现原来我的websocket路径,被shiro拦截了,在开发工具有会话session所以没有问题,但是真机调试没有会话session所以一直被拦截无法连接。在shiro配置上面取消对websocket拦截即可。【Ps:暂时还没研究到如何在小程序的websocket带token】参考链接4.

【请求头出现Provisionalheadersareshown】

5.

【webSocket连不上后端,webSocket被因为没有token拦截了】

6.

【websocket里面添加Token】

7.

【微信小程序WebSocket相关问题说明】

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎