php-curl 相关问题

HTTP请求的PHP cURL扩展

如何使用 PHP 和 Postman 来使用 Azure 应用程序角色

有关 Azure 应用程序角色和 PHP 的几个问题。 据我了解,我可以通过 REST API 或 Microsoft Graph 获取应用程序角色。我希望使用 API 路线并在 Stack 上找到了一些帖子

回答 1 投票 0

在 /media Whatsapp 云 api 上上传媒体文件时出现问题

我正在尝试通过 WhatsApp Cloud API 上传文件,因此我使用简单的 cURL 请求来执行此操作。 公共函数meta_upload_media2($token,$phonesid,$tipo,$archivo,$filename) { ...

回答 1 投票 0

cURL 无法连接到端口 80

我在 PHP 脚本中使用 cURL 来测试我的 API。当我尝试使用我的函数来获取数据时,它会抛出错误 错误:无法连接到 alenke.test 端口 80:连接被拒绝 但当我...

回答 2 投票 0

如何使用其 API 更新 Cloudflare 上的 WAF 规则

我正在尝试使用他们的 API 更新 Cloudflare 上的 waf 规则。你会在代码中看到我先获取规则和内容,然后更新规则。 所有凭证均正确 $zoneIdent...

回答 1 投票 0

PHP/CURL 冻结服务器

我有 php CURL 代码,通过 ajax 脚本运行。代码运行良好,没有问题,但我注意到,当执行代码时,整个服务器停止/冻结,直到 CURL 完成....

回答 1 投票 0

Shopify REST API 分页链接为空

情况 我正在尝试调用 Shopify REST API,其中有超过 50-250 个结果,但我无法从包含分页链接的 cURL 响应中获取链接标头。

回答 2 投票 0

通过docker套接字从容器内部执行PHPcurl

我面临着与此处描述的问题非常相似的问题:cURL request to Unix socket from php. 我正在运行一个 docker 容器,我想执行等效的 curl --unix-socket /var/run/d...

回答 1 投票 0

从端口 88 上的 URL 获取 JSON 数据时出现问题

我有生成 JSON 结果的 IPTV 的 URL。 URL 是(只有 24 小时在线,因此在任何人造成任何伤害之前它就会过期) http://mytv-extra.com:88/player_api.php?username=4240670294&pa...

回答 1 投票 0

如何更新firebase中现有的嵌套数组以通过curl添加新项目?

上面显示的是我的firebase实时数据库数据结构。目前msgs数组下只有一组数据,名称为119。我的要求是添加更多组数据(可能会出现...

回答 1 投票 0

HubSpot API - 获取过去 2 分钟内修改的联系人 - 获取一天前或更长时间修改的联系人

所以我的 HubSpot 帐户位于芝加哥中部时区,因此我通过设置默认时区来确保运行的 PHP 代码是相同的。 我正在尝试检索所有联系人

回答 1 投票 0

如何从Meta API(Whatsapp Media)下载媒体

我已按照官方链接上的文档进行操作并检索了媒体 URL https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media/#download-media 现在,一旦我有了 URL,我...

回答 1 投票 0

Amadeus API 错误:“代码”:32171,“标题”:“强制数据丢失

我正在尝试通过 Amadeus API 创建用于多城市航班搜索的应用程序,但出现错误。 这是我的 PHP 代码: $str=' { “起源目的地”:[ { “id&q...

回答 1 投票 0

如何使用 PHP Curl 或 Guzzle 客户端来使用动态用户代理标头

我是 PHP 新手,正在尝试调用 REST 服务。我可以使用 PHP 中的 Curl 或 Guzzle 客户端来做到这一点。稍后我会从 Mozilla 和 Chrome 浏览器调用它。 问题是Guzzle和Cu...

回答 2 投票 0

尝试使用curl时获取钻石替代代码

我正在尝试获取此页面的内容:https://www.realestate.com.au/nsw/karuah-2324/ 但是,当我使用以下代码获取页面内容时,我得到以下结果: �]R�r�@����wSlg�-�RSƼt�...

回答 1 投票 0

curl_exec 返回什么?

我正在尝试使用支付处理器设置 API。以下是他们向我提供的代码。 $result变量中有一些我想要的信息,我不明白的是变量是什么类型...

回答 1 投票 0

curl_close() 从 PHP 8 开始不写入 CURLOPT_COOKIEJAR 会话文件

对于那些遇到会话文件错误的人,其中 cURL 不会在 CURLOPT_COOKIEJAR 中写入任何内容(尽管该文件存在并且可写),请使用以下设置: PHP 8.0 及以上 有状态

回答 1 投票 0

PHP 8.0 及以上版本的 PHP cURL 会话存储中可能存在错误?

当我遇到一个奇怪的错误时,我正在处理有状态的 PHP cURL 请求。 这是重现问题的代码: 当我遇到一个奇怪的错误时,我正在处理 stateful PHP cURL 请求。 这是重现问题的代码: <?php // exit if not called from CLI if (php_sapi_name() !== 'cli') { die('This script can only be called from CLI'); } // exit if we don't have cURL support if (! function_exists('curl_init')) { die('This script requires cURL support'); } // get the major+minor version of PHP $phpVersion = substr(phpversion(), 0, 3); // get the version of the cUrl module (if available) $curlVersion = curl_version()['version']; echo "Testing with PHP {$phpVersion}, cURL {$curlVersion}\n"; // define our base path $basepath = dirname(__FILE__); // setup a randomic session file for cURL in the current directory, for debugging purposes $rand = md5(uniqid(rand(), true)); $sessionFile = "{$basepath}/{$rand}.txt"; file_put_contents($sessionFile, ''); // init a curl request to https://dba.stackexchange.com/questions/320782/any-benefit-in-replacing-a-varchar-for-an-index-in-the-main-table // you can use any URL that you know for sure will generate cookies on response $url = 'https://dba.stackexchange.com/questions/320782/any-benefit-in-replacing-a-varchar-for-an-index-in-the-main-table'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Encoding: utf-8', 'Accept-Charset: utf-8;q=0.7,*;q=0.7', 'Cache-Control: no-cache', 'Connection: Keep-Alive', 'Referer: https://www.google.com/', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0', ]); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // see https://curl.se/libcurl/c/CURLOPT_COOKIELIST.html curl_setopt($ch, CURLOPT_COOKIELIST, 'FLUSH'); curl_setopt($ch, CURLOPT_COOKIEJAR, $sessionFile); // this would not work even with CURLOPT_COOKIEFILE pointing to the same file curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30); // execute the request $response = curl_exec($ch); $error = curl_error($ch); $effectiveUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $primaryIp = curl_getinfo($ch, CURLINFO_PRIMARY_IP); curl_close($ch); // make the response a one-liner $response = preg_replace('/\s\s+/', ' ', str_replace([chr(13).chr(10), chr(10), chr(9)], ' ', $response)); // print the response (cap to a max of 1000 chars) echo "GET {$effectiveUrl} ({$httpStatusCode})\n"; echo "Primary IP: {$primaryIp}\n"; echo "Error: {$error}\n"; echo 'Response: '.substr($response, 0, 1000)."\n"; // debug the contents of the session file echo "Session file: {$sessionFile}\n"; // with PHP 8.0 onwards, this session file will be empty if (version_compare($phpVersion, '8.0', '>=')) { echo "Session file contents with PHP 8.x (BUGGED):\n"; echo 'Session Filesize: '.filesize($sessionFile)."\n"; echo file_get_contents($sessionFile)."\n"; } else { echo "Session file contents with PHP {$phpVersion} (WORKING):\n"; echo 'Session Filesize: '.filesize($sessionFile)."\n"; echo file_get_contents($sessionFile)."\n"; } 现在,如果你尝试: 使用 PHP 8.2.x 运行: file_get_contents() 上的 $sessionFile 将返回空字符串,同一文件的 filesize() 将是 0 使用大于 5.6 的任何其他 PHP 版本运行:file_get_contents() 上的 $sessionFile 将按预期返回数据 ,同一文件上的 filesize() 将大于零。 PHP 8.2 上的示例输出: maurizio:~/test (master ?DM) $ /usr/bin/php8.2 test.php Testing with PHP 8.2, cURL 7.81.0 GET https://dba.stackexchange.com/questions/65728/forcing-innodb-recovery-of-a-corrupted-database (200) Primary IP: 104.18.11.86 Error: Response: HTTP/2 200 date: .... (omissis) Session file: /home/maurizio/test/d38d7e5219cee96e64bd37d7bda568f6.txt Session file contents with PHP 8.x (BUGGED): Session Filesize: 0 PHP 7.4 上的示例输出: maurizio:~/test (master ?DM) $ /usr/bin/php7.4 test.php Testing with PHP 7.4, cURL 7.81.0 GET https://dba.stackexchange.com/questions/65728/forcing-innodb-recovery-of-a-corrupted-database (200) Primary IP: 104.18.10.86 Error: Response: HTTP/2 200 date: .... (omissis) Session file: /home/maurizio/test/3a573904bcc3509956d355a0d74ef2fe.txt Session file contents with PHP 7.4 (WORKING): Session Filesize: 431 # Netscape HTTP Cookie File # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. #HttpOnly_.stackexchange.com TRUE / TRUE 1696868681 __cf_bm OMISSIS-0-OMISSIS/E/OMISSIS= #HttpOnly_.stackexchange.com TRUE / TRUE 1728489281 prov OMISSIS-OMISSIS-OMISSIS-OMISSIS-OMISSIS 您能否确认您能够重现该错误,并确认这可能与 curl() 函数的内部工作有关? 无论如何,这很奇怪,因为文件存在并且是系统可读的。只有 PHP 无法可靠地访问此文件。 我还尝试使用 stream_get_contents 和 exec() 来读取这些文件,但输出相同。 请注意,在使用更知名的模式时我也面临着这个错误: curl_setopt($ch, CURLOPT_COOKIEFILE, $sessionFile); curl_setopt($ch, CURLOPT_COOKIEJAR, $sessionFile); 谢谢! 编辑1 我还尝试注册一个自定义关闭功能,只是为了看看是否有变化,并尝试使用旧的 fopen 和 fread // register a custom shutdown function to fetch the contents of the session file, when the script has ended register_shutdown_function(function () use ($sessionFile) { echo "Session file contents after shutdown:\n"; echo 'Session Filesize: '.filesize($sessionFile)."\n"; // try to acquire an exclusive lock on the session file, and read its contents $fp = fopen($sessionFile, 'r'); if (flock($fp, LOCK_EX)) { $sessContent = ''; while (! feof($fp)) { $sessContent .= fread($fp, 8192); } flock($fp, LOCK_UN); } fclose($fp); echo $sessContent; }); 这个也不走运 从 PHP 8.0.0 开始,curl_init()不再返回资源,而是返回CurlHandle类型的对象。 PHP 脚本退出后,垃圾收集器开始执行操作之前,该对象不会自动销毁。 CURLOPT_COOKIEJAR的文档指出: 关闭句柄时保存所有内部 cookie 的文件名,例如调用curl_close后。 当然,最后一部分具有误导性,因为根据其文档,从 PHP 8.0.0 curl_close() 起不再有任何效果。 如果您想强制关闭句柄(即销毁对象),您需要执行以下任一操作 unset($ch); 或 $ch = null;

回答 1 投票 0

cURL wiyh PHP - 连接 API REST - 令牌承载者

我正在尝试通过curl 使用vadesecure.com REST API。 (人:https://cloud-vadesecure-com.translate.goog/help/FR/admin/api/req/events.html?_x_tr_sl=auto&_x_tr_tl=fr&_x_tr_hl=fr) 我设法...

回答 1 投票 0

如何在谷歌共享驱动器上的文件夹之间移动文件

我编写了以下函数来在 Google 共享驱动器中的文件夹之间移动文件。它工作正常,没有任何错误,但文件没有移动。我能怎么做? 公共职能

回答 1 投票 0

如何验证Google共享云端硬盘中是否存在文件夹

我编写了以下函数来检查Google Drive中是否存在文件夹。它可以正常工作,但如果该文件夹位于共享驱动器中,则无法工作。我能怎么做? 公共函数 ExistsFolderOn...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.