curl发送信息POST方法

时间:2014-02-14 04:00:41

标签: php curl

我正在尝试使用HTMLPOST表单curl传递数据,是否有人知道如何执行此操作?  我的代码:(dtda.php)

<?php 
// HTTP authentication 
$url = "http://siteapi.com.br:9988/api"; 
$ch = curl_init();     
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_URL, $url);  
curl_setopt($ch, CURLOPT_USERPWD, "Teste:123456");  
$result = curl_exec($ch);  
curl_close($ch);  
echo $result; 
?>

我的第二个代码HTML :( sending.html)

<form name="myform" id="myform" action="http://endereco.com.br/dtda.php" method="post" >
<input type="text" name="op" value="event"/> 
<input type="text" name="seq" value="45" />
<input type="text" name="type" value="nexttrack" />
<input type="text" name="priority" value="1" />
<input type="submit" style="padding-left:10px; padding-right:10px" class="button   compact" onclick="javascript:openlive()"  value="Ativar agendamento" /><p></form> <br /><br />
 </form>

当我将表格数据传递给“endereco.com.br/dtda.php”时?

2 个答案:

答案 0 :(得分:0)

try

$url = "http://siteapi.com.br:9988/api"; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, 
http_build_query(array('yourData' => $data)));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);
curl_close ($ch);

答案 1 :(得分:0)

如果您想将发布的数据转发到其他网址,可以像这样添加:

curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('php://input'));