用PHP将请求发布到表单
我试图向一个站点发送一个POST请求,该站点有一个指向tcl脚本的表单。 我可以在页面的源代码中看到-用PHP将请求发布到表单,php,forms,http,post,Php,Forms,Http,Post,我试图向一个站点发送一个POST请求,该站点有一个指向tcl脚本的表单。 我可以在页面的源代码中看到- <FORM method=post action=<script>.tcl name=form1 密码“=>…); $options=array('http'=>array('method'=>'POST','content'=>http\u build\u query($data)); $context=stream\u context\u create($option
<FORM method=post action=<script>.tcl name=form1
密码“=>…);
$options=array('http'=>array('method'=>'POST','content'=>http\u build\u query($data));
$context=stream\u context\u create($options);
$result=file\u get\u contents($url,false,$context);
var_dump($结果);
但我收到:file\u get\u contents(..)-无法打开流:HTTP请求失败!HTTP/1.0 500内部服务器错误
我是新手,所以我会感谢你的帮助。
谢谢。看起来是一份适合你的工作
例如:
<?php
$url = '<url>/<script>.tcl';
$data = array('Username' => ... , 'Password' => ...);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
// Return the response...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;
您需要使用cURL。谢谢,我更改了它,现在得到-由于此服务器上的系统错误,无法访问请求的URL。您的URL是否受到某种保护,如htaccess?我得到了相同的结果-由于此服务器上的系统错误,无法访问请求的URL。您的服务器是否安装了cURL在数组中('curl',获取加载的扩展名())
您确定url正确吗?
<?php
$url = '<url>/<script>.tcl';
$data = array('Username' => ... , 'Password' => ...);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
// Return the response...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);
echo $response;