Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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,我想知道如何将我页面上的post/submit数据发送到这些网站?该网站有“主机、时间、端口”。我的MYSQL数据库有一个URL列表。我正在考虑卷曲,但我不确定 请有人张贴的例子。它必须是一种快速的方法 基本上是对url和post进行feteches while($resultSet = mysql_fetch_array($SQL)){ $ch = curl_init($resultSet['url'] . $fullcurl);

我正在使用curl,我想知道如何将我页面上的post/submit数据发送到这些网站?该网站有“主机、时间、端口”。我的MYSQL数据库有一个URL列表。我正在考虑卷曲,但我不确定

请有人张贴的例子。它必须是一种快速的方法

基本上是对url和post进行feteches

while($resultSet = mysql_fetch_array($SQL)){                
    $ch = curl_init($resultSet['url'] . $fullcurl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 2);           
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
}
表示
CURLOPT_POST
选项设置为
true
,使其成为POST请求
CURLOPT\u POSTFIELDS
设置将以
foo=bar&spam=eggs
格式发送的字段(可以使用
http\u build\u query
从数组生成)

试一试:

while ($resultSet = mysql_fetch_assoc($SQL)) {
  $ch = curl_init($resultSet['url']);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_TIMEOUT,2);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $fullcurl);
  $response = curl_exec($ch);
  curl_close();
}

下面是一个如何使用curl_multi执行此操作的示例。虽然你应该把它分开,这样你一次只能有一定数量的URL(即30个)。我添加了follow location指令,这是您通常需要的

$mh = curl_multi_init();
$ch = array();
while($resultSet = mysql_fetch_array($SQL)){                
    $ch[$i] = curl_init($resultSet['url'] . $fullcurl);
    curl_setopt($ch[$i], CURLOPT_TIMEOUT, 2);
    curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch[$i], CURLOPT_FOLLOWLOCATION, true);
    curl_multi_add_handle($mh, $ch[$i]);
}
$running = null;
do {
    curl_multi_exec($mh,$running);
} while ($running > 0);
$num = count($ch);
for ($i=0; $i<$num; $i++ ) {
    curl_multi_remove_handle($mh, $ch[$i]);
}
curl_multi_close($mh);
$mh=curl_multi_init();
$ch=array();
而($resultSet=mysql\u fetch\u数组($SQL)){
$ch[$i]=curl_init($resultSet['url'].$fullcurl);
curl_setopt($ch[$i],CURLOPT_超时,2);
curl_setopt($ch[$i],CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch[$i],CURLOPT_FOLLOWLOCATION,true);
卷曲多加把手($mh,$ch[$i]);
}
$running=null;
做{
curl_multi_exec($mh,$running);
}而($running>0);
$num=计数($ch);

对于($i=0;$iI),您的问题让我有点困惑。是关于发送POST数据(我回答了),还是关于发送多个请求?向我的数据库中的多个URL发送$host、$time、$port。我已经有了类似的“$fullcurl=”?host=“$fullcurl=”?here=“.here=.cash=.cash=.weet=.weet=.weet=”。还有什么帮助吗?我已经打开了“$ch=curl\u init($resultSet['url'].$fullcurl);”,建议替换什么?我有这个编码为“curl\u multi\u add\u handle($mh,$ch);“…这里有点困惑。再次需要一些帮助不要将fullcurl添加到url中..它是postfields。它应该是key=value&key2=value2格式..删除$fullcurl开头的问号并运行我的代码。请问,这些部分是做什么的?”curl_setopt($ch[$I],CURLOPT_FOLLOWLOCATION,true);“curl_multi_exec($mh,$running)}($running>0);$num=count($ch);对于($i=0;$iAlso,“curl\u setopt($ch[$i],CURLOPT\u TIMEOUT,2);”我研究并发现这个“usleep(100000);”它们是做什么的?请在代码上添加注释。
$mh = curl_multi_init();
$ch = array();
while($resultSet = mysql_fetch_array($SQL)){                
    $ch[$i] = curl_init($resultSet['url'] . $fullcurl);
    curl_setopt($ch[$i], CURLOPT_TIMEOUT, 2);
    curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch[$i], CURLOPT_FOLLOWLOCATION, true);
    curl_multi_add_handle($mh, $ch[$i]);
}
$running = null;
do {
    curl_multi_exec($mh,$running);
} while ($running > 0);
$num = count($ch);
for ($i=0; $i<$num; $i++ ) {
    curl_multi_remove_handle($mh, $ch[$i]);
}
curl_multi_close($mh);