Android 앱에서 내 서버 (학교 서버)의 PHP 파일로 데이터를 보내려고하지만 몇 가지 문제가 있습니다. 나는 SimpleHelix을 통해 내 자신의 호스팅 공간이, 나는 잘 데이터를 보낼 수 있었다,하지만 난 내 학교의 서버를 사용하려고하면 PHP 프로그램은 다음과 같은 오류 반환 :Android에서 PHP 로의 HTTP POST가 특정 도메인에서 작동하지 않습니다.
Notice: Undefined index: message in /home/alespurg/test_good.php on line 4
Warning: file_put_contents(androidmessages.html) [function.file-put-contents]: failed to open stream: Permission denied in /home/alespurg/test_good.php on line 9
Warning: file_get_contents(androidmessages.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/alespurg/test_good.php on line 11
모든 내가 변경된를 내 Java 파일은 게시에 필요한 URL입니다. 게시물이 통과하지 못하도록 내 학교의 서버에 제한이있을 수 있습니까? 폴더와 파일에 대한 사용 권한을 모두 확인했는데 모두 775입니다. 다시 프로그램이 작동한다는 것을 알았습니다. 서버에 문제가 있습니다. 나는 그 도메인의 IP 주소를 사용하지 않았다. 학교의 서버에서 찾지 못했습니다.
편집 :
<?php
// get the "message" variable from the post request
// this is the data coming from the Android app
$message=$_POST["message"];
// specify the file where we will save the contents of the variable message
$filename="androidmessages.html";
// write (append) the data to the file
file_put_contents($filename,$message."<br />",FILE_APPEND);
// load the contents of the file to a variable
$androidmessages=file_get_contents($filename);
// display the contents of the variable (which has the contents of the file)
echo $androidmessages;
?>
현실적인 도움을주기 위해 게시하는 오류와 내용을 생성하는 PHP 코드를 확인해야합니다. – Charles
원본 코드에 PHP 코드를 추가했습니다. 감사합니다 – mkyong
오, 어떻게 간단한 코드를 사랑해! 게시 된 데이터를 표시 할 수 있습니까? 데이터에'message' 키가 누락 된 것 같습니다 ... – Charles