Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于PHP的帮助_Php_Curl - Fatal编程技术网

关于PHP的帮助

关于PHP的帮助,php,curl,Php,Curl,我在玩cURL,我很难让它工作。我希望cURL脚本将数据发布到该表单上,以便在results.txt中查看发布的数据。这是我的表单脚本,然后是我的cURL脚本。我在这里发布之前更改了$url 编辑:问题是,它没有发布数据。我运行了cURL脚本,并检查了results.txt以查找post数据“有效”,但它不存在。另外,如果有什么不同,我使用的是DreamHost 更新:我明白了!有趣的事。我的目标是带有表单的页面,而不是处理帖子的页面 <html> <head>

我在玩cURL,我很难让它工作。我希望cURL脚本将数据发布到该表单上,以便在results.txt中查看发布的数据。这是我的表单脚本,然后是我的cURL脚本。我在这里发布之前更改了$url

编辑:问题是,它没有发布数据。我运行了cURL脚本,并检查了results.txt以查找post数据“有效”,但它不存在。另外,如果有什么不同,我使用的是DreamHost

更新:我明白了!有趣的事。我的目标是带有表单的页面,而不是处理帖子的页面

<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>
My cURL脚本源代码:

    $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);


?>
<?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的字符串。尝试改用数组。前任:
数组('anything'=>'WORKS')

您正在传递一个带有CURLOPT_POSTFIELDS的字符串。尝试改用数组。前任:
数组('anything'=>'WORKS')

它不是发布“作品”,你能把它变为dump($result)?最好检查curl是否返回error@RageZ它返回“bool(true)”您确定问题不在于您的响应脚本吗?试着做一个
var\u dump
$\u POST
。我真的不知道。我应该把它放在write.php中吗?它不是发布“作品”,你能var_dump($result)?最好检查curl是否返回error@RageZ它返回“bool(true)”您确定问题不在于您的响应脚本吗?试着做一个
var\u dump
$\u POST
。我真的不知道。我应该把它放在write.php中吗?返回什么状态码?echo curl_getinfo($ch,CURLINFO_HTTP_代码);警告:curl_getinfo():第49行的domain.com/code-lab/curl.php中的1不是有效的curl句柄资源第49行是echo curl_getinfo($ch,CURLINFO_HTTP_code);在curl\u exec()之后添加行,但在curl\u close()之前添加行之后,我看到数字“200”。返回的状态码是什么?echo curl_getinfo($ch,CURLINFO_HTTP_代码);警告:curl_getinfo():第49行的domain.com/code-lab/curl.php中的1不是有效的curl句柄资源第49行是echo curl_getinfo($ch,CURLINFO_HTTP_code);在curl\u exec()后面加一行,但在curl\u close()前面加一行。加上它之后,我看到了数字“200”。