0

post 変数をオンラインのフォームに渡して情報を返す php スクリプトを作成しようとしています。次のコマンドを使用してコマンドラインを使用して、これを正常に実行しました。

curl --data "cid=800.10" http://online.starmont.ca/java/www?html=main

残念ながら、これをphpで動作させることはできないようです。誰かが何か提案があれば、それは大歓迎です。前もって感謝します。これが私が現在持っているPHPスクリプトです。

<?php

//set up a connection variable for the page you will post data to
$curl_connection = curl_init('http://online.starmont.ca/java/www?html=main');

//curl basic setup
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//$_POST variables to pass
$post_item = 'cid='.strip_tags($_POST['800.10']);

//format the $post_items into a string
$post_string = implode ('&', $post_items);

//send the $_POST data to the new page
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);

print ($result);
curl_close($curl_connection);
?>
4

2 に答える 2

0

また、設定する必要があります

curl_setopt($curl_connection, CURLOPT_POST, true);

POSTcurl にリクエストを実行させるため。

詳細については、http ://www.php.net/curl_setopt をご覧ください。

于 2013-10-16T05:31:46.413 に答える