从 Android 到 PHP 的 HTTP POST 不适用于某些域

发布于 2024-12-27 18:58:40 字数 1296 浏览 0 评论 0原文

我正在尝试将数据从 Android 应用程序发送到我的服务器(学校服务器)上的 PHP 文件,但遇到了一些问题。我通过 SimpleHelix 拥有自己的托管空间,并且能够很好地发送数据,但是当我尝试使用学校的服务器时,PHP 程序返回以下错误:

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;
?>

I am trying to send data from an Android app to a PHP file on my server (school server) but I'm running into some problems. I have my own hosting space through SimpleHelix, and I was able to send the data just fine, but when I try to use my school's server, the PHP program returns the following error:

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

All I have changed in my Java file is the URL that I need it to post to. Could there be restrictions on my school's server that prevent the post to go through? I've checked my permissions on the folders and files, they're all 775. Again, I know the program works, I'm just having problems with the server. I did not use the IP address of the domain for either one. I couldn't find it for my school's server.

EDIT:

<?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;
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2025-01-03 18:58:40

如果权限为 775,则意味着 Web 服务器进程不是 (1) 拥有 /home/alespurg/ 的用户(不太可能)或 (2) 拥有 /home/alespurg/ 的组的成员(也不太可能),那么它将无法写入该目录。

您确定 Web 服务器进程是 /home/alespurg/ 的所有者或所有权组的成员吗?

我假设您的 Web 服务器是 apache,通常以 apache:apachenobody:nobody 的形式运行。从目录结构来看,/home/alespurg/ 可能属于 alespurg:alespurg 或某些派生文件。


附录

如果您需要做这样的事情,apache 进程并不是真正合适的地方。您可能不知道,但您可以编写 php 脚本并从服务器上的 shell 环境执行它们您以适当的用户身份登录以写入该目录。此外,如有必要,您可以让 CRON 为您运行它们。 Web 服务器进程是一个不必要的中间人。

If the permissions are 775 that means that if the web server process isn't either (1) the user who owns /home/alespurg/ (not likely) or (2) a member of the group that owns /home/alespurg/ (also not likely) then it won't be able write to the directory.

Are you sure the web server process is the owner or a member of the ownership group for /home/alespurg/?

I'll assume your web server is apache, which usually runs as apache:apache or nobody:nobody. Judging from the directory structure, it's likely that /home/alespurg/ is owned by alespurg:alespurg or some derivation.


ADDENDUM

If you need to do things like this an apache process is not really the appropriate place. You may not know it but you can write php scripts and execute them from the shell environment on your server where you're logged in as the appropriate user to write to that directory. Further, you can have CRON run them for you if necessary. The web server process is an unnecessary middleman.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文