Java 在eclipse中无法从real server发送或接收数据,但同一程序在localhost上执行良好

Java 在eclipse中无法从real server发送或接收数据,但同一程序在localhost上执行良好,java,android,eclipse,Java,Android,Eclipse,此代码适用于localhost,但会发出一些警告,并且无法从服务器发送或接收任何数据。php文件能够在调用链接http://*****/check.php时显示消息。但从服务器调用时无法显示任何内容 try{ httpclient=new DefaultHttpClient(); httppost= new HttpPost("http://10.0.2.2/check.php"); // make sure the url is cor

此代码适用于localhost,但会发出一些警告,并且无法从服务器发送或接收任何数据。php文件能够在调用链接http://*****/check.php时显示消息。但从服务器调用时无法显示任何内容

try{            

        httpclient=new DefaultHttpClient();
        httppost= new HttpPost("http://10.0.2.2/check.php"); // make sure the url is correct.
        //add your data
        nameValuePairs = new ArrayList<NameValuePair>(2);
        // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
        nameValuePairs.add(new BasicNameValuePair("username",et.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
        nameValuePairs.add(new BasicNameValuePair("password",pass.getText().toString().trim())); 
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        //Execute HTTP Post Request
        response=httpclient.execute(httppost);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        final String response = httpclient.execute(httppost, responseHandler);
        System.out.println("Response : " + response); 
        runOnUiThread(new Runnable() {
            public void run() {
                tv.setText("Response from PHP : " + response);
                dialog.dismiss();
            }
        });

        if(response.equalsIgnoreCase("User Found")){
            runOnUiThread(new Runnable() {
                public void run() {
                    Toast.makeText(MainActivity.this,"Login Success", Toast.LENGTH_SHORT).show();
                }
            });

            startActivity(new Intent(MainActivity.this, UserPage.class));
        }else{
            showAlert();                
        }

    }catch(Exception e){
        dialog.dismiss();
        System.out.println("Exception : " + e.getMessage());
    }
}
public void showAlert(){
    MainActivity.this.runOnUiThread(new Runnable() {
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle("Login Error.");
            builder.setMessage("User not Found.")  
                   .setCancelable(false)
                   .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                       }
                   });                     
            AlertDialog alert = builder.create();
            alert.show();               
        }
    });
}

例外:内部服务器错误意味着这可能与服务器设置有关,而不是与客户端代码有关。我已经检查了php连接和其他内容。看起来还不错。因此,如果无法找出内部服务器错误背后的原因,您可能需要尝试发布关于服务器的另一个问题,并包含PHP脚本。内部服务器错误意味着您的服务器和/或脚本肯定有问题。对PHP问题有更好理解的人可能会帮助您,
W/SingleClientConnManager(312): Invalid use 
of SingleClientConnManager: connection still allocated.
W/SingleClientConnManager(312): Make sure to release 
the  connection before allocating another one.
D/dalvikvm(312): GC_FOR_MALLOC freed 3302 objects / 175320 bytes in 153ms
D/dalvikvm(203): GC_EXPLICIT freed 203 objects / 13616 bytes in 137ms
I/System.out(312): Exception : Internal Server Error
W/InputManagerService(58): Window already focused,   ignoring focus gain 
of:   com.android.internal.view.IInputMethodClient$Stub$Proxy@43fd5720
D/dalvikvm(262): GC_EXPLICIT freed 761 objects / 55032 bytes in 150ms
D/SntpClient(58): request time failed: java.net.SocketException: 
Address family not supported by protocol