[英]What's wrong with this PHP code to send POST data via a stream?
我正在尝试使用PHP脚本通过发布到登录页面来登录另一个网站(在本例中为Moodle安装)。
此代码似乎部分起作用。 问题在于,接收方只能识别第一个参数。 对于下面显示的代码,仅识别“用户名”参数。 但是,如果切换“用户名”和“密码”的顺序,以便首先列出“密码”,则使用$ _POST ['password']仅识别“密码”。
$postdata = http_build_query(
array(
'username' => $currentUser,
'password' => $userPassword,
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($loginURL, false, $context);
关于为什么只识别第一个参数的任何想法?
好的,我现在看到代码是正确的,并且外部因素正在干扰POST请求。 这段代码是在Drupal内部运行的,所以我认为这与它有关。 当我将其另存为.php文件时,它可以按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.