预期HTTP 101响应,但为';403禁止';在Android WebSocket中-反应本机
我用react native制作了一个国际象棋应用程序,我用websocket发送和接收我的请求, 当我在ios中运行我的应用程序时,一切正常,但当我在android中运行我的应用程序时,web套接字未打开并返回“预期HTTP 101响应,但“403被禁止” 我的创建游戏代码:预期HTTP 101响应,但为';403禁止';在Android WebSocket中-反应本机,android,react-native,websocket,Android,React Native,Websocket,我用react native制作了一个国际象棋应用程序,我用websocket发送和接收我的请求, 当我在ios中运行我的应用程序时,一切正常,但当我在android中运行我的应用程序时,web套接字未打开并返回“预期HTTP 101响应,但“403被禁止” 我的创建游戏代码: createGame() { const { playConfig } = this.props; fetch('https://en.lichess.org/setup/ai', { me
createGame() {
const { playConfig } = this.props;
fetch('https://en.lichess.org/setup/ai', {
method: 'POST',
headers: {
Accept: 'application/vnd.lichess.v2+json',
'Content-Type': 'application/json',
},
body: playConfig,
})
.then(res => res.json())
.then(this.onGameCreated);
}
onGameCreated = res => {
const { game } = this.state;
const socketUrl = res.url.socket;
const clientId = Math.random().toString(36).substring(2);
clearInterval(this.interval);
this.wsReady = false;
let url = `wss://socket.lichess.org${socketUrl}?sri=${clientId}&mobile=1`;
this.ws = new WebSocket(
url,
);
this.ws.onmessage = e => {
// a message was received
console.log(`received: ${e.data}`);
const data = JSON.parse(e.data);
let moveData;
let victor;
if (data.t === 'move' && data.v > game.history().length) {
moveData = data.d;
} else if (data.t === 'end') {
victor = data.d;
} else if (data.t === 'b') {
// b for batch
const first = data.d[0];
if (first) {
if (first.d.status && first.d.status.name === 'mate') {
moveData = first.d;
}
if (first.t === 'end') {
victor = first.d;
}
if (first.d.winner) {
victor = first.d.winner;
}
}
}
if (victor) {
dongSound.play();
this.setState({
victor,
});
this.ws = null;
} else if (moveData) {
const { uci, clock } = moveData;
const castle = moveData.castle;
let from = uci.substring(0, 2);
let to = uci.substring(2, 4);
if (castle && castle.king) {
from = castle.king[0];
to = castle.king[1];
}
this.board.movePiece(to, from);
if (clock) {
this.latestClock = clock;
}
}
};
this.ws.onerror = e => {
// an error occurred
console.log(e.message);
};
this.ws.onopen = () => {
this.wsReady = true;
dongSound.play();
this.setState({
initialized: true,
userColor: res.player.color === 'white' ? 'w' : 'b',
});
console.log('ws open');
// ping every second
this.interval = setInterval(
() => {
this.sendMessage({
t: 'p',
v: game.history().length,
});
},
1000,
);
};
};
有人知道吗?
提前感谢您似乎没有权限在此Web服务器上打开套接字。
我认为问题不在于Java代码,而在于web服务器的配置。但在ios中,一切都正常,web套接字是开放的。我也有同样的问题。我甚至可以通过Android中的firefox连接,但不能通过我的应用程序。我绑定了okhttp3和JavaWebSocket包,两者都导致了相同的错误。你找到解决办法了吗?