确保在执行GET请求时将查询字符串放在URL的末尾。从curl_setopt()
docs为CURLOPT_HTTPGET
(强调)
$qry_str = "?x=10&y=20";
$ch = curl_init();
// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, 'http://example.com/test.php' . $qry_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$content = trim(curl_exec($ch));
curl_close($ch);
print $content;
With a POST you pass the data via the CURLOPT_POSTFIELDS option instead
of passing it in the CURLOPT__URL.
-------------------------------------------------------------------------
$qry_str = "x=10&y=20";
curl_setopt($ch, CURLOPT_URL, 'http://example.com/test.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
// Set request method to POST
curl_setopt($ch, CURLOPT_POST, 1);
// Set query data here with CURLOPT_POSTFIELDS
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry_str);
$content = trim(curl_exec($ch));
curl_close($ch);
print $content;
注:
[设置CURLOPT_HTTPGET等于] TRUE
到复位 HTTP请求方法得到的。
由于GET是默认值,因此只有在请求方法已更改时才需要。
请小心Get请求。谷歌与他们玩得很开心。 ;) – NotMe 2009-08-04 02:11:10
@Chris - 一位朋友发现,当他建立一个通过GET请求管理用户贡献内容的网站时,这是一种艰难的方式。 Googlebot乐于遵循所有'删除'链接,并带来可预测的结果。 – 2009-08-04 18:59:34