Android:无法通过应用程序调用Java Web服务
我正在尝试使用url通过android应用程序调用web服务,但我收到的错误是resonse http代码为0,onFailure内容为null。我可以使用移动浏览器打开和传递参数,但当我运行我的应用程序时,它会在onFailure方法中抛出else部分的错误“发生意外错误![大多数Android:无法通过应用程序调用Java Web服务,java,android,apache,rest,tomcat,Java,Android,Apache,Rest,Tomcat,我正在尝试使用url通过android应用程序调用web服务,但我收到的错误是resonse http代码为0,onFailure内容为null。我可以使用移动浏览器打开和传递参数,但当我运行我的应用程序时,它会在onFailure方法中抛出else部分的错误“发生意外错误![大多数 AsyncHttpClient client = new AsyncHttpClient(); client.get("http://198.168.43.250:8081/TrekServerTest2
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://198.168.43.250:8081/TrekServerTest2/rest/register/doregister",params ,new AsyncHttpResponseHandler() {
// When the response returned by REST has Http response code '200'
@Override
public void onSuccess(String response) {
// Hide Progress Dialog
prgDialog.hide();
try {
// JSON Object
JSONObject obj = new JSONObject(response);
// When the JSON response has status boolean value assigned with true
if(obj.getBoolean("status")){
// Set Default Values for Edit View controls
setDefaultValues();
// Display successfully registered message using Toast
Toast.makeText(getApplicationContext(), "You are successfully registered!", Toast.LENGTH_LONG).show();
}
// Else display error message
else{
//errorMsg.setText(obj.getString("error_msg"));
Toast.makeText(getApplicationContext(), obj.getString("error_msg"), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "Error Occured [Server's JSON response might be invalid]!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
// When the response returned by REST has Http response code other than '200'
@Override
public void onFailure(int statusCode, Throwable error,
String content) {
Toast.makeText(getApplicationContext(), ""+statusCode+ "e:"+content, Toast.LENGTH_LONG).show();
// Hide Progress Dialog
prgDialog.hide();
// When Http response code is '404'
if(statusCode == 404){
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
// When Http response code is '500'
else if(statusCode == 500){
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
// When Http response code other than 404, 500
else{
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
}
}
});
您好,在清单中添加internet权限?是的,我已添加该权限