我可以通过php curl中的get方法发送一个包含卷曲括号的参数

发布于 2025-02-12 07:51:37 字数 136 浏览 9 评论 0原文

我正在研究应用程序API。我正在尝试创建一个使用PHP提取数据的机器人。简而言之,我需要在GET方法下发送一个参数,此参数包含一个JSON数据,因此我用卷曲括号介绍它,但是当我这样做时,PHP curl无法正常工作,我向URL提出了请求我不想要,你能帮我吗?

I'm working on application APIs. I'm trying to create a bot to pull data with php. In short, I need to send a parameter under the GET method, this parameter contains a json data, so I cover it with curly brackets, but when I do this, php curl does not work properly and I make a request to a url that I do not want, can you help me please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

做个少女永远怀春 2025-02-19 07:51:37

使用JSON_ENCODE()创建JSON和urlencode()将其正确编码以在URL中使用。

$param = urlencode(json_encode(['need' => 'help']));
curl_setopt($ch, CUROPT_URL, "example.com/api/?params=$param");

Use json_encode() to create the JSON, and urlencode() to encode it properly for use in a URL.

$param = urlencode(json_encode(['need' => 'help']));
curl_setopt($ch, CUROPT_URL, "example.com/api/?params=$param");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文