使用react native webview转到localhost时获取net :: ERR_CONNECTION_REFUSED:9000/login

use*_*131 2 android webview react-native

对不起,如果这是一个愚蠢的问题,但我是新手,并试图了解.

我的节点服务器在localhost:9000上运行,我正在尝试使用webview.这是我想要回归的 -

      <View style={[styles.container]}>
        <WebView
          ref={'webview'}
          automaticallyAdjustContentInsets={false}
          style={styles.webView}
          source={{uri: 'http://localhost:9000/login'}}
          javaScriptEnabled={true}
          onNavigationStateChange={this.onNavigationStateChange.bind(this)}
          startInLoadingState={true}
          scalesPageToFit={true}
        />
      </View>
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用,因为我收到以下错误:

Encountered an error loading page Object {canGoForward: false, code: -6, canGoBack: false, description: "net::ERR_CONNECTION_REFUSED", loading: false…}canGoBack: falsecanGoForward: falsecode: -6description: "net::ERR_CONNECTION_REFUSED"loading: falsetarget: 9title: ""url: "http://localhost:9000/login"__proto__: ObjectreactConsoleError @ ExceptionsManager.js:76console.error @ YellowBox.js:48onLoadingError @ WebView.android.js:300proxiedMethod @ createPrototypeProxy.js:44invokeGuardedCallback @ ReactErrorUtils.js:26executeDispatch @ EventPluginUtils.js:87executeDispatchesInOrder @ EventPluginUtils.js:110executeDispatchesAndRelease @ EventPluginHub.js:42executeDispatchesAndReleaseTopLevel @ EventPluginHub.js:53forEachAccumulated @ forEachAccumulated.js:26processEventQueue @ EventPluginHub.js:215runEventQueueInBatch @ ReactEventEmitterMixin.js:18handleTopLevel @ ReactEventEmitterMixin.js:29(anonymous function) @ ReactNativeEventEmitter.js:122perform @ Transaction.js:136batchedUpdates @ ReactDefaultBatchingStrategy.js:63batchedUpdates @ ReactUpdates.js:97_receiveRootNodeIDEvent @ ReactNativeEventEmitter.js:121receiveEvent @ ReactNativeEventEmitter.js:135__callFunction @ MessageQueue.js:185(anonymous function) @ MessageQueue.js:89guard @ MessageQueue.js:43callFunctionReturnFlushedQueue @ MessageQueue.js:88onmessage @ debuggerWorker.js:39

当我将源uri作为http://google.com或其他东西时,webview工作正常.有人可以帮忙吗?谢谢

Dan*_*dow 8

localhost将是Android设备本身.要从Android模拟器中访问您的主机操作系统,您可以使用10.0.2.2:9000或您的实际IP地址.


Vya*_*huk 5

就个人而言,我更喜欢做 adb reverse tcp:9000 tcp:9000