gpt4 book ai didi

php - 使用包含 GET url 的参数的 CURL Get 请求

转载 作者:IT王子 更新时间:2023-10-29 00:21:05 29 4
gpt4 key购买 nike

我正在尝试制作一个 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

关于php - 使用包含 GET url 的参数的 CURL Get 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32596371/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com