连接错误node.js服务器。android中显示无法访问主机的Http请求
我使用loopj库进行http请求,使用genymotion进行测试。我还想在我的移动设备上进行测试,但每当我点击按钮调用onclick函数时,它就会显示主机在每个ip上都无法访问 代码如下:连接错误node.js服务器。android中显示无法访问主机的Http请求,android,node.js,mongodb,web-services,loopj,Android,Node.js,Mongodb,Web Services,Loopj,我使用loopj库进行http请求,使用genymotion进行测试。我还想在我的移动设备上进行测试,但每当我点击按钮调用onclick函数时,它就会显示主机在每个ip上都无法访问 代码如下: public void onClick(View view) { username = emailET.getText().toString(); password = pwdET.getText().toString(); Asyn
public void onClick(View view) {
username = emailET.getText().toString();
password = pwdET.getText().toString();
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("username", username);
params.put("password", password);
client.post("http://10.0.3.2:3000/index", params, new TextHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, String res) {
try {
JSONObject obj = new JSONObject(res);
if(obj.getString("success").equals("true")){
Toast.makeText(getApplicationContext(),"Service connected", Toast.LENGTH_LONG);
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Server not connected",Toast.LENGTH_LONG);
}
// called when response HTTP status is "200 OK"
}
@Override
public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
Toast.makeText(getApplicationContext(),"Bad Request",Toast.LENGTH_LONG);
}
}
);
下面是node.js和mongodb服务器运行的代码片段:
图像作为链接上载图像作为链接上载