[英]Connection Upgrade on React-Native
所以我目前正在使用React-Native開發一個應用程序,我必須實現Websocket。 現在,我正在嘗試將我的應用程序連接到Mattermost。 對於ws,我們必須從html get請求開始,該請求將升級為ws請求。 范例:
URL: https://URL/api/v3/users/websocket
Méthod : GET
Adress : 10.10.10.10:8080
Code d’état : 200
Response (39 o)
Server "nginx"
Date "Tue, 08 Aug 2017 12:33:21 GMT"
Connection "upgrade"
Upgrade "websocket"
Sec-WebSocket-Accept "vG2CYVx3/p+6ei/8e5fGMN8qq7A="
Request's header (769 o)
Host "URL"
User-Agent "Mozilla/5.0 (Windows NT 6.1; … Gecko/20100101 Firefox/54.0"
Accept "text/html,application/xhtml+x…lication/xml;q=0.9,*/*;q=0.8"
Accept-Language "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"
Accept-Encoding "gzip, deflate, br"
Sec-WebSocket-Version "13"
Origin "URL"
Sec-WebSocket-Extensions "permessage-deflate"
Sec-WebSocket-Key "HsX9INf0fr7x0cQAglMyjg=="
Cookie "MMAUTHTOKEN=7xaaaaaaaaahezhatnwxwih;"
Connection "keep-alive, Upgrade"
Upgrade "websocket"
所以我的問題是如何在react上進行可升級的連接,並使用它來建立wss連接。
目前,我正在使用axios進行我的html請求和用於我的websocket連接的socket.io。
好的,找到解決方案。 剛剛下載了該驅動程序並將其包含在我的應用程序中:
import Websocket from "../Applications/websocket_client"
export default class SecWatt extends Component {
constructor(props){
super(props);
}
componentDidMount(){
webs = new Websocket();
webs.setEventCallback(printEvent);
webs.initialize("wss://*MattermostURL*/api/v3/users/websocket" , "YourToken");
}
render()
{
return(
<View>
</View>
);
}
}
function printEvent(msg){
console.log(msg);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.