React Native和Websockets(sockets.io)的XMLHttpRequest错误

时间:2017-05-10 11:51:22

标签: reactjs react-native websocket xmlhttprequest

我无法让React-Native使用sockets.io。我有一个运行sockets.io的服务器,并希望通过(Android版本的)React-Native连接到此服务器。我现在在执行时遇到以下错误:

\node_modules\react-native\Libraries\Core\ExceptionsManager.js:63 Failed to set the 'responseType' property on 'XMLHttpRequest': The response type cannot be set after the request has been sent.

我不确定要粘贴哪些相关代码,因为它并没有真正告诉我它失败的线索,也不是我自己直接调用XMLHttpRequest,但我想这是因为它转换了socket io连接到XMLHttp。虽然我对这一点并不是100%肯定,但这只是我在网上采访的内容,对我来说这是一个相当新的话题。

任何人都可以对此提供一些见解吗?

这是完整的堆栈跟踪:

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

对后人来说,这就是解决方案。 我不得不改变:

const socket = io.connect(`$ {BASECONNECTION}:$ {PORT}`);

为:

const socket = io(`$ {BASECONNECTION}:$ {PORT}`,{transports:[' websocket']} );