서버에서 PHP 스크립트를 호출하는 HTTP GET 요청을 가진 안드로이드 클라이언트가 있습니다. 데이터베이스를 쿼리하고 결과 행을 에코하는 내 서버의 PHP 스크립트 .. 이제는 어떻게 blob 파일과 다른 파일을 분리합니까? 응답에서 필드 ?? PHP 코드가 망가 졌다고 생각합니다. 올바른 방향으로 나를 가리키면 도움이 될 것입니다. 고마워요!HttpResponse에서 이진 파일 및 다른 매개 변수를 얻는 방법?
My android code:
HttpClient httpClient = new DefaultHttpClient();
StringBuilder uriBuilder = new StringBuilder("http://192.168.x.x/file_download.php");
HttpGet request = new HttpGet(uriBuilder.toString());
HttpResponse response = httpClient.execute(request);
int status = response.getStatusLine().getStatusCode();
Log.i("Http Get",response.getStatusLine().toString());
// we assume that the response body contains the error message
if (status != HttpStatus.SC_OK) {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
response.getEntity().writeTo(ostream);
Log.e("HTTP CLIENT", ostream.toString());
} else {
// InputStream content = response.getEntity().getContent();
// <consume response>
String type = response.getEntity().toString();
content.close(); // this will also close the connection
}
내 PHP 코드 :
<?php
$conn = mysql_connect("localhost", "root", "root");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("MYDB")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
$sql = "SELECT title, filetype, mode, data, time, application, entity_id
FROM table
WHERE id=(select max(id) from file)";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
$rows = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$rows[]=$row;
}
echo $rows;
mysql_free_result($result);
?>
안녕하세요, 고맙습니다. 저는 json 파싱을 서버와 클라이언트 측에서 모두 사용했으며 매력과 같이 작동합니다. 감사합니다 !! –