Java Localhost解析与android模拟器的集成

Java Localhost解析与android模拟器的集成,java,android,parse-platform,android-emulator,parse-server,Java,Android,Parse Platform,Android Emulator,Parse Server,我正在尝试在本地主机上设置解析服务器,并尝试连接到我的应用程序模拟器 这是我的解析代码 // Example express application adding the parse-server module to expose Parse // compatible API routes. var express = require('express'); var ParseServer = require('parse-server').ParseServer; var databas

我正在尝试在本地主机上设置解析服务器,并尝试连接到我的应用程序模拟器

这是我的解析代码

// Example express application adding the parse-server module to expose Parse
// compatible API routes.

var express = require('express');
var ParseServer = require('parse-server').ParseServer;

var databaseUri = process.env.DATABASE_URI;

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://abc:27017/parse',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'chat-test',
  masterKey: process.env.MASTER_KEY || 'chat-test', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
  facebookAppIds: 'abc' //FaceBook App ID Keys. Comma Separated.
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey

var app = express();

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);

// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
  res.status(200).send('I dream of being a web site.');
});

var port = process.env.PORT || 1337;
app.listen(port, function() {
    console.log('parse-server-example running on port ' + port + '.');
});
我正在使用

Parse.initialize(new Parse.Configuration.Builder(getBaseContext()).applicationId("chat-test").server("http:/localhost:1337/parse/").build());
我从LiveServer上获得了这一切,并将其替换为localhost,但我无法让android连接到localhost。它给了我i/o故障


如何使我的android模拟器与本地主机解析一起工作?android模拟器实际上是一个虚拟机,这意味着本地主机是模拟器的内部IP。您可以通过ip
10.0.2.2
访问您的计算机

这意味着您应该将URL更改为
http://10.0.2.2:1337/parse/

完整的代码行应为:

Parse.initialize(新建Parse.Configuration.Builder(getBaseContext()).applicationId(“聊天测试”).server(“http://10.0.2.2:1337/parse/);

这是有文档记录的

Android模拟器实际上是一个虚拟机,这意味着localhost是模拟器的内部IP。您可以通过ip
10.0.2.2
访问您的计算机

这意味着您应该将URL更改为
http://10.0.2.2:1337/parse/

完整的代码行应为:

Parse.initialize(新建Parse.Configuration.Builder(getBaseContext()).applicationId(“聊天测试”).server(“http://10.0.2.2:1337/parse/);

这是有据可查的

为什么代码中有localhost?Localhost意味着请求在本地设备上运行,您可以在服务器内部使用它,但不能在客户端设备上使用。尝试将服务器/计算机的IP地址放在那里,也得到了回答


为什么代码中有localhost?Localhost意味着请求在本地设备上运行,您可以在服务器内部使用它,但不能在客户端设备上使用。尝试将服务器/计算机的IP地址放在那里,也得到了回答


是什么导致i/o失败?您的确切错误或logcat是什么?是什么导致i/o失败?您的确切错误或日志是什么?
.server("http://localhost:1337/parse/")