안녕하세요 ^^
php를 이용해 자바에서 컨텐츠를 받아오려합니다. 전체적인 구성은 안드로이드에서 컨텐츠 번호가 저장되는 변수를 post로 php 로 보내서 php 가 데이터 베이스에서 해당하는 자료들을 JSON으로 변환해 다시 안드로이드로 보내주는 방식입니다.
근데 안드로이드에서 보면 아무 자료도 받아오질 못합니다. 예를 들어 $content_no 대신에 305 라는 컨텐츠 번호를 집어넣 으면 해당 자료를 잘 받아옵니다. (때문에 안드로이드엔 이상이 없다고 생각합니다)
이래저래 해보니까 php 에서 변수를 제대로 받나 확인하려고 인서트 구문을 추가했는데
디비에 이상하게 저장되더라고요, 값이 2개가 저장되는데 1개는 변수값이 정확하고 하나는 빈값인데
이것때문에 자료를 못불러오는것 같은데 이거 왜그런건가요? ㅠ
참고사진 밑에 자료불러오는건 php select 함수에 변수값($c_no)을 안쓰고 컨텐츠 번호를 직접 넣은겁니다
<?
// define('__XE__', true);
$DB['host'] = 'localhost';
$DB['db'] = '디비';
$DB['id'] = '아이디';
$DB['pw'] = '아이디';
$regsqli = new mysqli($DB['host'], $DB['id'], $DB['pw'], $DB['db']);
$Re = array();
$c_no = $_POST['no_content'];
$res = mysqli_query($regsqli,"select object_id from wp_term_relationships where term_taxonomy_id
LIKE '13'");
$zz = mysqli_query($regsqli,"insert into Regid (regid) values ('$c_no')");
//변수 제대로 받았나 확인용
$Re = array();
$res4 = mysqli_query($regsqli,"select guid from wp_posts where post_parent
LIKE '".$c_no."' and post_type LIKE 'attachment' ");
while($result4 = mysqli_fetch_array($res4)){
array_push($Re,
array('post_content'=>$result4[0]
));
}
echo json_encode(array("little_known"=>$Re));
//끝
?>
아래는 안드로이드 코드입니다.
private class HttpConnectionThread extends AsyncTask<String, Void, String> {
String sResult;
@Override
protected String doInBackground(String... sId) {
sResult = "NO";
String respond;
try {
String body = "no_content=" + content_no;
URL u = new URL("http://honjapan.com/post_content.php");
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setReadTimeout(4000);
huc.setConnectTimeout(4000);
huc.setRequestMethod("POST");
huc.setDoInput(true);
huc.setDoOutput(true);
huc.setRequestProperty("utf-8", "application/x-www-form-urlencoded");
OutputStream os = huc.getOutputStream();
os.write(body.getBytes("utf-8"));
os.flush();
os.close();
BufferedReader is = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
int ch;
StringBuffer sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char) ch);
}
if (is != null) {
is.close();
}
sResult = sb.toString();
} catch (Exception e) {
}
return sResult;
}
}
