[英]Android - 403 Forbidden on Form Submission
我创建了一个用户注册活动,该活动显示一个表单,并在提交时通过HTTP Post将数据发送到承载insert.php文件的URL。 该主机当前是我的桌面,并且正在运行WAMP服务器。
当我通过虚拟模拟器运行应用程序时,数据将正确提交,并且可以通过检查MySQL数据库进行验证。
当我在Android手机上调试应用程序时,连接成功,但未提交数据。 我在php脚本返回的HTML布局中得到403 Forbidden
。 当我查看Android日志时
有什么线索可能导致问题吗?
insert.php代码段
$host='127.0.0.1';
$uname='root';
$pwd='';
$db="user_db";
$conn = new mysqli($host, $uname,$pwd, $db);
$name=$_REQUEST['name'];
$password=$_REQUEST['password'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
$sql = "INSERT INTO user (name, password, email, mobile)
VALUES ('$name', '$password', '$email', '$mobile')";
print(json_encode($flag));
也就是说,Apache禁止您使用手机使用的IP地址访问该站点。
开箱即用WAMPServer被设计为开发工具,因此,为了安全起见,对Apache的访问仅限于运行WAMPServer(Apache)的单个设备。 如果不是运行WAMPServer,而是运行其他WAMP堆栈之一,则其基本相同。
编辑您的httpd.conf文件并更改安全性配置,请找到本节
<Directory "c:/wamp/www/">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride all
#
# Controls who can get stuff from this server.
#
# onlineoffline tag - don't remove
Require local
# Add a line to allow access from your local network(wifi) if thats what you are using
# to get from the phone to the PC running WAMPServer
Require ip 192.168.1
请注意,仅使用IPV4网络子网的4个四分位数中的3个。 这将允许192.168.1.1-192.168.1.255范围内的任何IP,以防万一电话在另一天获得不同的IP。
保存httpd.conf文件,然后使用wampmanager图标菜单重新启动Apache:
left click wampmanager->Apache->Service->Restart Service
如果您使用的是手机,移动数据访问,那么这将是一个更大的问题,因为您将不得不转发路由器以允许从外部访问Apache,并添加其他安全访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.