2012-10-26 21 views
0

我正在尝试向具有指向tcl脚本的表单的网站发送POST请求。 我可以在页面的源代码见 -以PHP形式发送请求以形成

<FORM method=post action=<script>.tcl name=form1 

我试着写一个PHP脚本,将请求发送

$url = '<url>/<script>.tcl'; 
$data = array('Username' => ... , 'Password' => ...); 
$options = array('http' => array('method' => 'POST','content' => http_build_query($data))); 
$context = stream_context_create($options); 
$result = file_get_contents($url, false, $context); 

var_dump($result); 

但我得到:的file_get_contents(..) - 未能打开流: HTTP请求失败! HTTP/1.0 500内部服务器错误

即时通讯新的在此,所以我将不胜感激您的帮助。 谢谢。

+0

你需要使用卷曲。 –

+0

谢谢,我改变了它,现在我得到了 - 由于此服务器上的系统错误,所请求的URL无法访问。 – Blondy314

+1

您的网址是否受某些东西(如htaccess)的保护? – DijkeMark

回答

1

看起来像cURL的工作。

例如:

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

我得到了相同的结果 - 由于此服务器上的系统错误,所请求的URL无法访问。 – Blondy314

+1

您的服务器是否安装了卷曲? 'in_array('curl',get_loaded_extensions())'你确定这个url是正确的吗? – Lex