簡體   English   中英

PHP的cURL幫助

[英]cURL help with PHP

我正在使用cURL,但無法使其正常工作。 我希望cURL腳本在該表單上發布數據,以便可以在results.txt中看到發布的數據。 這是我的表單腳本,然后是我的cURL腳本。 我在此處發布之前更改了$ url。

編輯:問題是,它沒有發布數據。 我運行了cURL腳本,並檢查了result.txt來查找發布數據“ WORKS”,並且該數據不存在。 另外,如果有什么不同,我正在使用DreamHost。

更新:我知道了! 有趣的事情。 我將目標指向具有表單的頁面,而不是處理POST的頁面。

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
    <title>Test</title>
  </head>

  <body>
    <form method="POST" name="TestForm" action="write.php">
      <p />
      Input anything: <input type="text" name="anything" value="Default"/> <br />
      <input type="submit" value="OK" name="submit" />
    </form>
  </body>
</html>

write.php代碼源

    $stringData1 = $_POST["anything"];
    $myFile = "results.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "Bobby Bopper\n";
    fwrite($fh, $stringData);
    fwrite($fh, $stringData1);
    fclose($fh);


?>

我的cURL腳本代碼源:

<?php

$url = "http://www.domain.com/submit/index.php";


$useragent="YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";

$ch = curl_init();


curl_setopt($ch, CURLOPT_USERAGENT, $useragent);


curl_setopt($ch, CURLOPT_URL, $url);


curl_setopt($ch, CURLOPT_POST, 1);


curl_setopt($ch, CURLOPT_POSTFIELDS, "anything=WORKS");


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


print "<br/> test" . $result;

?>

您正在使用CURLOPT_POSTFIELDS傳遞字符串。 嘗試改用數組。 例如:array('anything'=>'WORKS');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM