Android Post To Server,访问日志中有奇怪的消息


Android Post To Server, strange message in access log

我正在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;
    }
?>

下面是androidcrash .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方法应该将post数据添加到数组
  3. 中。
  1. "Apache-HttpClient/UNAVAILABLE (java 1.4)"只是由请求发送的user-agent字符串。(Android HTTP User Agent)

  2. 看起来不像错误。看起来你从你的帖子到"/API/ReceiveData.php"得到了一个200 OK的响应。这就是为什么它会出现在你的访问日志里。这就是一个成功请求的样子。请看这里(http://httpd.apache.org/docs/current/logs.html#combined)

是什么让你觉得出了问题?