0

我正在研究 android/php 项目。我想做的是创建一个库,将崩溃详细信息上传到我的服务器。

我有一个测试应用程序,它故意抛出 NullPointerException。这会调用我的库,然后获取各种信息,例如设备详细信息和崩溃详细信息。

然后应该将这些值的内容发布到我的 Web 服务器,然后将数据存储在我的数据库中。

库没有发生错误,但 apache 日志中有一条奇怪的消息,更奇怪的是它在访问日志中而不是错误日志中。我不知道它是否在 android 项目中或 PHP 页面没有做我期望他们做的事情。

以下是我从 Android 发布数据的方式

CrashReporter.severity = severity;
        CrashReporter.exceptionObject = exceptionObject;

        String exceptionType = CrashReporter.exceptionObject.getClass().getName();
        Log.d("Exception Type", exceptionType);
        Log.d("Device Name", android.os.Build.MODEL);
        Log.d("Device Brand", android.os.Build.BRAND);
        Log.d("Android API Level", String.valueOf(android.os.Build.VERSION.SDK_INT));
        Log.d("Android Name", CommonTasks.convertApiLevelToAndroidName(android.os.Build.VERSION.SDK_INT));
        Log.d("Screen Resolution", CritiMon.appContext.getResources().getDisplayMetrics().widthPixels + " x " + CritiMon.appContext.getResources().getDisplayMetrics().heightPixels);
        Log.d("Exception", exceptionObject.toString());
        Log.d("Severity", severity.toString());

            new Thread(new Runnable() {

                @Override
                public void run() {
                    try
                    {
                    String exceptionType = CrashReporter.exceptionObject.getClass().getName();
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost("http://192.168.1.74/API/ReceiveData.php");

                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("platform", "Android"));
                    nameValuePairs.add(new BasicNameValuePair("exceptionType", exceptionType));
                    nameValuePairs.add(new BasicNameValuePair("deviceName", android.os.Build.MODEL));
                    nameValuePairs.add(new BasicNameValuePair("devicBrand", android.os.Build.BRAND));
                    nameValuePairs.add(new BasicNameValuePair("apiLevel", String.valueOf(android.os.Build.VERSION.SDK_INT)));
                    nameValuePairs.add(new BasicNameValuePair("androidName", CommonTasks.convertApiLevelToAndroidName(android.os.Build.VERSION.SDK_INT)));
                    nameValuePairs.add(new BasicNameValuePair("screenResolution", CritiMon.appContext.getResources().getDisplayMetrics().widthPixels + " x " + CritiMon.appContext.getResources().getDisplayMetrics().heightPixels));
                    nameValuePairs.add(new BasicNameValuePair("exception", CrashReporter.exceptionObject.toString()));
                    nameValuePairs.add(new BasicNameValuePair("severity", CrashReporter.severity.toString()));

                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                    HttpResponse response = httpClient.execute(httpPost);
                    InputStream is = response.getEntity().getContent();
                    BufferedInputStream bis = new BufferedInputStream(is);
                    ByteArrayBuffer baf = new ByteArrayBuffer(20);

                    int current = 0;
                    while ((current = bis.read()) != -1)
                    {
                        baf.append((byte)current);
                    }

                    Log.d("HTTP Response", new String(baf.toByteArray()));
                    }
                    catch (ClientProtocolException ex)
                    {
                        Log.e("ClientProtocolException", ex.toString());
                    }
                    catch (IOException ex)
                    {
                        Log.e("IOException", ex.toString());
                    }
                }
            }).start();

下面是 ReceiveData.php 文件

<?php

    include ("../config.php");
    include ("CommonTasks.php");

    $commonTasks = new CommonTasks();

    if (empty($_POST))
    {
        $commonTasks->setAlarm("Test", "POST WAS EMPTY", ALARM_WARNING, $_SERVER['REQUEST_URI']);
        exit();
    }
    switch ($_POST['platform'])
    {
        case "Android":
            include ("AndroidCrash.php");
                $androidCrash = new AndroidCrash($_POST);
                echo $androidCrash->submitToDatabase($_POST);
                break;
        default:
            $commonTasks->setAlarm("API Receive Data", "Unknown platform detected", ALARM_WARNING, $_SERVER['REQUEST_URI']);
            echo "Error 500 - Unsupported platform detected";
            break;
    }
?>

下面是 AndrioidCrash.php 文件

<?php
    include ("../config.php");
    include ("SettingsManager.php");
    include ("CommonWork.php");

    class AndroidCrash
    {
        var $type;
        var $deviceName;
        var $deviceBrand;
        var $apiLevel;
        var $androidName;
        var $screenResolution;
        var $exception;
        var $severity;

        function __construct($post)
        {
            /*$this->type = $type;
            $this->deviceName = $deviceName;
            $this->deviceBrand = $deviceBrand;
            $this->apiLevel = $apiLevel;
            $this->androidName = $androidName;
            $this->screenResolution = $screenResolution;
            $this->exception = $exception;
            $this->severity = $severity;*/

            $fh = fopen('log.txt', 'w');
            fwrite($fh, print_r($post, true));
            fclose($fh);

            $commonWork = new CommonTasks();
            $commonWork->setAlarm("Test", print_r($post, true), ALARM_WARNING, $_SERVER['REQUEST_URI']);
        }

        function submitToDatabase($post)
        {
            $fh = fopen('log.txt', 'w');
            fwrite($fh, print_r($post, true));
            fclose($fh);

            $commonWork = new CommonTasks();
            $commonWork->setAlarm("Test", print_r($post, true), ALARM_WARNING, $_SERVER['REQUEST_URI']);

            return "200 OK";
        }
    }
?>

apache 文件中有我不明白的消息。

192.168.1.76 - - [15/Jun/2013:16:20:37 +0100] "POST /API/ReceiveData.php HTTP/1.1" 200 - "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"

所以基本上我有两个问题:

  1. Apache-HttpClient/UNAVAILABLE 是什么意思
  2. 什么会导致上述错误。commonTasks->setAlarm 方法应该将发布数据添加到数组中
4

1 回答 1

1
  1. “Apache-HttpClient/UNAVAILABLE (java 1.4)”只是请求发送的用户代理字符串。请参阅此处(Android HTTP 用户代理

  2. 它看起来不像一个错误。看起来您的帖子对“/API/ReceiveData.php”的响应为 200 OK。这就是为什么它在您的访问日志中。这正是成功请求的样子。见这里(http://httpd.apache.org/docs/current/logs.html#combined

是什么让你认为任何事情都是错误的?

于 2013-06-15T15:28:35.133 回答