我正在尝试用 curl 替换使用 url(例如 .../?id=123)的传递参数。如果无法使用 curl,请忽略。
我试着在网上寻找例子,但我只能看到如何发布数据但没有得到它。我在其中一个网站上得到了这个,但我失去了它的参考。
$post_data['ID'] = '1';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection = curl_init('posturl.php');
//set options
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, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request8
$curlresult = curl_exec($curl_connection);
//show information regarding the request
// print_r(curl_getinfo($curl_connection));
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
//close the connection
curl_close($curl_connection);
我如何从 posturl.php 获取参数
有没有人可以发布和使用 curl 的示例?