0

我再次回到你身边,因为我只是被封锁了。我想执行存储在服务器中的 php 文件,为此,我使用了该代码:

@Override
        protected Void doInBackground(Void... params) {
           // Network operation
            String url = "http://192.168.1.4/android_connect/get_all_surveys.php";
            HttpClient client = new DefaultHttpClient();
            try {

              client.execute(new HttpGet(url));
              Log.d("EXECUTED",client.execute(new HttpGet(url)).toString());
            } catch(IOException e) {
              Log.d("EXCEPTION EXECUTION",e.toString());
            }
            return null;
        }

我想表明该日志Log.d("EXECUTED",client.execute(new HttpGet(url)).toString());已显示,因此执行 php 脚本的那一行肯定有问题,client.execute(new HttpGet(url));而不仅仅是一个 http get 请求?谢谢您的帮助。

4

2 回答 2

2

你的代码看起来不错。但是您无缘无故地执行了两次 GET 请求(也没有“执行 PHP 脚本”-您只是在执行 GET 请求。它将在服务器上触发的操作是另一回事)。

替换此代码:

client.execute(new HttpGet(url));
Log.d("EXECUTED",client.execute(new HttpGet(url)).toString());

和:

HttpResponse response = client.execute(new HttpGet(url));
Log.d("EXECUTED: " + response );
于 2012-11-19T12:27:46.710 回答
0

访问 URL 时,客户端通常不需要关心背后使用的技术。这个 Android 应用程序和其他任何应用程序一样都是客户端,因此它不需要“激活”它尝试连接的 PHP 脚本。此脚本的行为取决于服务器应用程序。

于 2012-11-19T12:28:51.763 回答