带有包含 GET url 参数的 CURL Get 请求
CURL Get Request with a parameter that contains a GET url
我正在尝试创建一个 cURL GET
来抓取 Facebook Graph 对象:
GET https://graph.facebook.com/?id=**OBJECT_URL**&scrape=true&method=post
在我的例子中,OBJECT_URL
包含 GET
个参数:
https://www.example.com/og.php?a=b&c=d
出于这个原因,我不能将它作为 file_get_contents()
或 CURLOPT_URL
中的 GET
参数,因为它会变成这样:
https://graph.facebook.com/?id=**https://www.example.com/og.php?a=b&c=d**&scrape=true&method=post
有没有办法以类似于 CURLOPT_POSTFIELDS
的方式将其作为 GET
参数传递?
您需要转义您的参数,http_build_query 函数将很有用:
$query = http_build_query([
'id' => 'http://foo?a=1&b=2',
'scrape' => true,
'method' => 'post'
]);
$url = "https://graph.facebook.com/?".$query;
var_dump($url);
这将输出:
https://graph.facebook.com/?id=http%3A%2F%2Ffoo%3Fa%3D1%26b%3D2&scrape=1&method=post
我正在尝试创建一个 cURL GET
来抓取 Facebook Graph 对象:
GET https://graph.facebook.com/?id=**OBJECT_URL**&scrape=true&method=post
在我的例子中,OBJECT_URL
包含 GET
个参数:
https://www.example.com/og.php?a=b&c=d
出于这个原因,我不能将它作为 file_get_contents()
或 CURLOPT_URL
中的 GET
参数,因为它会变成这样:
https://graph.facebook.com/?id=**https://www.example.com/og.php?a=b&c=d**&scrape=true&method=post
有没有办法以类似于 CURLOPT_POSTFIELDS
的方式将其作为 GET
参数传递?
您需要转义您的参数,http_build_query 函数将很有用:
$query = http_build_query([
'id' => 'http://foo?a=1&b=2',
'scrape' => true,
'method' => 'post'
]);
$url = "https://graph.facebook.com/?".$query;
var_dump($url);
这将输出:
https://graph.facebook.com/?id=http%3A%2F%2Ffoo%3Fa%3D1%26b%3D2&scrape=1&method=post