微信小程序使用WebSocket的坑-微信小程序使用缺点-微信小程序的优缺点
微信小程序使用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相关问题说明】
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

