我正在开发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)"
基本上我有两个问题:
答案 0 :(得分:1)
“Apache-HttpClient / UNAVAILABLE(java 1.4)”只是请求发送的用户代理字符串。见这里(Android HTTP User Agent)
看起来不像是错误。看起来您的帖子中有200 OK回复“/API/ReceiveData.php”。这就是它在您的访问日志中的原因。这正是成功的请求的样子。见这里(http://httpd.apache.org/docs/current/logs.html#combined)
是什么让你觉得有什么不对的?