curl 相关问题

cURL是一个库和命令行工具,用于使用各种协议(如HTTP,FTP和SFTP)传输数据。 cURL项目生成两个产品libcurl和cURL。无论使用哪种cURL产品,此标签都涵盖cURL的所有用法

通过 Curl/php 从 Plaid 获取访问令牌

我正在尝试从 Plaid 获取访问令牌密钥,但我似乎无法从 Plaid 的任何人那里获得任何帮助。 我在使用产品时遇到问题: $client_id = getenv("PLAID_CLIENT_ID"); $secr...

回答 1 投票 0

我们可以使用访问密钥和密钥来创建用户吗

我想确认是否可以通过curl或Python使用访问密钥和秘密密钥以编程方式创建AWS IAM用户。具体来说,我有兴趣了解

回答 1 投票 0

如何让 axios 使用 AWS ACM 公共证书?

我很惊讶地发现AWS ACM颁发的公共证书在使用axios和node-fetch时会触发“无法验证第一个证书”的错误。然而,当我使用curl f...

回答 1 投票 0

如何解决【curl:(60)SSL证书问题:证书链中的自签名证书】

我想在我的 Linux 计算机上安装 nvm。 (我的Debian版本是10,Git版本是2.27。OPENSSL版本是1.1.1d 2019年9月10日) 我读了这个文档 https://github.com/nvm-sh/nvm#inst...

回答 2 投票 0

安装插件或检查更新时出错

我面临着 10 月 CMS 的挑战。每当我尝试安装插件或检查后端设置的更新时,我都会遇到以下错误: 使用未定义的常量 CURLOPT_FOLLOWLOCATION -

回答 1 投票 0

10 月 CMS 问题:安装插件或检查更新时出错

大家! 🌟 我面临着 October CMS 的挑战。每当我尝试安装插件或检查后端设置的更新时,我都会遇到以下错误: 使用未定义常量

回答 1 投票 0

从 CURL 请求流式响应,无需等待其完成

我的服务器上有一个 PHP 脚本,它正在向另一台服务器发出图像请求。 该脚本的访问方式就像常规图像源一样,如下所示: 我的服务器上有一个 PHP 脚本,它正在向另一台服务器发出图像请求。 该脚本的访问方式就像常规图像源一样: <img src="http://example.com/imagecontroller.php?id=1234" /> 浏览器 -> 脚本 -> 外部服务器 该脚本正在向外部服务器发出 CURL 请求。 是否可以在服务器收到 CURL 响应时将其直接“流”回客户端(浏览器)? 假设我的脚本位于速度缓慢的共享托管服务器上,而外部服务器速度极快(CDN)。有没有办法将响应直接返回给客户端,而我的脚本不会成为瓶颈?如果我的服务器在开始响应客户端之前不必等待整个图像加载到内存中,那就太好了。 将 -N/--no-buffer 标志传递给 curl。它执行以下操作: 禁用输出流的缓冲。正常工作中 在这种情况下,curl 将使用标准缓冲输出流 其效果是它将以块的形式输出数据,而不是 必然恰好是数据到达的时间。使用此选项将 禁用该缓冲。 请注意,这是记录的否定选项名称。因此你可以使用 --buffer 强制执行缓冲。 是的,您可以使用 CURLOPT_WRITEFUNCTION 标志: curl_setopt($ch, CURLOPT_WRITEFUNCTION, $callback); 其中 $ch 是 Curl 处理程序,$callback 是回调函数名称。 该命令将从远程站点传输响应数据。回调函数可能类似于: $result = ''; $callback = function ($ch, $str) { global $result; $result .= $str;//$str has the chunks of data streamed back. //here you can mess with the stream data either with $result or $str return strlen($str);//don't touch this }; 如果最后没有中断$result将包含来自远程站点的所有响应。 查看 Pascal Martin 对一个不相关问题的回答,其中他讨论了使用 CURLOPT_FILE 来流式传输卷曲响应。他对处理“操纵一个长度为 3000 万个字符的字符串”的解释应该适用于您的情况。 希望这有帮助! 不使用curl,您可以使用fsocket进行流式传输。 a) php curl 没有 --no-buffer,它只存在于 CLI 版本 b)虽然可以回显甚至刷新写入功能,但它不会实时刷新到屏幕。 IE。如果您在回调中设置计时器/睡眠,那么您会发现,curl_exec() 基本上不会接收回调中的每一位并立即从刷新渲染到浏览器,而是将其保留,因为它仍然需要等待回调本身完成以触发写入函数。因此,在回调中睡眠 5 秒将导致卷曲运行并保持 5 秒,直到所有刷新的元素将回显到缓冲区,然后刷新。 例如。在下面的示例中,如果在卷曲的 url 路由上调用的函数正在流式传输响应 - 每 2 秒等待一次并用刷新回显以将其推送通过卷曲,并且您尝试捕获并解析它以下内容 - 它不会实时流式传输 - 因为curl本身仍然处于调用中,并且在调用本身结束之前不会处理write函数。之后,它会像实时运行但包含所有数据一样运行 write 函数,因此它只会呈现给浏览器,或者如果您尝试通过缓冲区生成它,则会生成单个响应。 curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); //put response into an output var /// flush each out at a time curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($curl, $data) use (&$result) { echo $data.' <br><br>'; while (ob_get_contents()) {ob_flush();}flush(); @ob_end_flush(); if(strstr($data,'||--ENDOFDATA--||')){return -1;} return strlen($data); }); curl_exec($ch); curl_close($ch); return; 无论您是尝试将curl作为作为yieling函数传递的回调来运行,还是尝试从curl函数中yield,将生成器返回到家长电话。 用 guzzle 或类似的东西代替。

回答 5 投票 0

使用 cuRL 测试时,Php 脚本返回完整日志

使用 php 做我的第一步,我有点困惑。我编写了一个小脚本,它应该接受带有一些数据的 POST 请求,将数据放入格式化的电子邮件中并发送。为此我只是

回答 1 投票 0

curl:密码中的引号字符用于基本授权

我正在尝试使用curl调用具有基本授权的API,并且遇到密码包含特殊字符的问题,特别是引号(“)。我如何发送请求...

回答 1 投票 0

当sleep和usleep功能被禁用时如何暂停php线程?

php 5.6 版本运行在虚拟主机上,因此 sleep 和 usleep 功能被禁用,我没有权限启用它们。 我必须将脚本挂起一段时间才能继续

回答 1 投票 0

在初始 SOCKS5 响应 phpcurl 中收到无效版本

我正在尝试使用带有curl和PHP的socks5代理从我的API接收数据。 但无论我尝试什么,我都会收到此错误 Received invalid version in initial SOCKS5 response 我已经尝试过谷歌所有我...

回答 1 投票 0

无法将curl转换为python cdoe

我正在尝试从网站获取数据。 我可以运行下面的脚本,使用curl成功并获取响应数据 卷曲'https://gappapi.deliverynow.vn/api/dish/get_delivery_dishes?id_type=2&request_id=112...

回答 1 投票 0

telnet 后关闭curl 连接

我想要什么: 连接成功后,我希望curl能够成功退出。我正在容器内运行此命令,因此我希望curl命令成功退出,以便容器...

回答 3 投票 0

如何使用Curl同时发布文件和JSON数据?

我一直在用这个curl命令发布一个文件: curl -i -F file=@./File.xlsm -F name=file -X POST http://example.com/new_file/ 现在我想发送一些有关该文件的信息(作为 JSON)......

回答 5 投票 0

JSON 解码返回 NULL

我向 URL 发出了一个curl请求,得到了这个 JSON $data {“状态”:200,“消息”:“成功”,“数据”:[{“cpe_mac”:“665544332211”,“设备...

回答 2 投票 0

“cURL 库执行失败:尽管在基于 ARM 的 Windows Surface 7 上进行了正确的编译和环境路径设置,但未找到‘libcurl-x64.dll’”

我正在尝试使用 cURL 库(我对库很陌生,所以我为我的无知道歉)。我使用命令: g++ -I"C:/Curl/include" distance.cpp -o run -L"C:\Program Files\...

回答 1 投票 0

如何从github邀请中获取invitation_id

我正在使用 github api 接受并列出存储库邀请。我正在使用这个链接。 尽管如此,我还是不知道从哪里可以获得invitation_id并将其添加到接受请求中...

回答 2 投票 0

通过 cURL 从 PHP 中的 POST 表单发送文件

我正在编写一个 API,我想处理从表单 POST 上传的文件。表单的标记并不太复杂: < 我正在编写一个 API,我想处理从表单上传的文件 POST。表单的标记并不太复杂: <form action="" method="post" enctype="multipart/form-data"> <fieldset> <input type="file" name="image" id="image" /> <input type="submit" name="upload" value="Upload" /> </fieldset> </form> 但是,我很难理解如何处理此服务器端并与 cURL 请求一起发送。 我熟悉使用带有数据数组的 cURL 发送 POST 请求,并且我读过的有关上传文件的资源告诉我在文件名中添加 @ 符号作为前缀。但这些相同的资源有一个硬编码的文件名,例如 $post = array( 'image' => '@/path/to/myfile.jpg', ... ); 这是哪个文件路径?我在哪里可以找到它?是否会类似于 $_FILES['image']['tmp_name'],在这种情况下我的 $post 数组应该如下所示: $post = array( 'image' => '@' . $_FILES['image']['tmp_name'], ... ); 或者我的处理方式是错误的吗?任何建议将不胜感激。 编辑:如果有人能给我一个代码片段,说明我将使用以下代码片段去哪里,那么我将不胜感激。我主要关注的是我将作为 cURL 参数发送的内容,以及如何在接收脚本中使用这些参数的示例(为了论证,我们将其称为 curl_receiver.php)。 我有这个网络表格: <form action="script.php" method="post" enctype="multipart/form-data"> <fieldset> <input type="file" name="image /> <input type="submit" name="upload" value="Upload" /> </fieldset> </form> 这将是script.php: if (isset($_POST['upload'])) { // cURL call would go here // my tmp. file would be $_FILES['image']['tmp_name'], and // the filename would be $_FILES['image']['name'] } 这是一些将文件发送到 ftp 的生产代码(可能对您来说是一个很好的解决方案): // This is the entire file that was uploaded to a temp location. $localFile = $_FILES[$fileKey]['tmp_name']; $fp = fopen($localFile, 'r'); // Connecting to website. $ch = curl_init(); curl_setopt($ch, CURLOPT_USERPWD, "[email protected]:password"); curl_setopt($ch, CURLOPT_URL, 'ftp://@ftp.website.net/audio/' . $strFileName); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 86400); // 1 Day Timeout curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_NOPROGRESS, false); curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'CURL_callback'); curl_setopt($ch, CURLOPT_BUFFERSIZE, 128); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localFile)); curl_exec ($ch); if (curl_errno($ch)) { $msg = curl_error($ch); } else { $msg = 'File uploaded successfully.'; } curl_close ($ch); $return = array('msg' => $msg); echo json_encode($return); 对于找到这篇文章并使用 PHP5.5+ 的人来说,这可能会有所帮助。 我发现 netcoder 建议的方法不起作用。即这不起作用: $tmpfile = $_FILES['image']['tmp_name']; $filename = basename($_FILES['image']['name']); $data = array( 'uploaded_file' => '@'.$tmpfile.';filename='.$filename, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 我会在 $_POST var 中收到 'uploaded_file' 字段 - 而在 $_FILES var 中什么也没有。 事实证明,对于 php5.5+ 有一个新的 curl_file_create() 函数需要使用。所以上面的内容就变成了: $data = array( 'uploaded_file' => curl_file_create($tmpfile, $_FILES['image']['type'], $filename) ); 由于 @ 格式现已弃用。 这应该有效: $tmpfile = $_FILES['image']['tmp_name']; $filename = basename($_FILES['image']['name']); $data = array( 'uploaded_file' => '@'.$tmpfile.';filename='.$filename, ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set your other cURL options here (url, etc.) curl_exec($ch); 在接收脚本中,您将拥有: print_r($_FILES); /* which would output something like Array ( [uploaded_file] => Array ( [tmp_name] => /tmp/f87453hf [name] => myimage.jpg [error] => 0 [size] => 12345 [type] => image/jpeg ) ) */ 然后,如果你想正确处理文件上传,你可以这样做: if (move_uploaded_file($_FILES['uploaded_file'], '/path/to/destination/file.zip')) { // do stuff } 对于我来说,@符号不起作用,所以我做了一些研究,发现这种方法对我有用,我希望这对你有帮助。 $target_url = "http://server:port/xxxxx.php"; $fname = 'file.txt'; $cfile = new CURLFile(realpath($fname)); $post = array ( 'file' => $cfile ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data')); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result = curl_exec ($ch); if ($result === FALSE) { echo "Error sending" . $fname . " " . curl_error($ch); curl_close ($ch); }else{ curl_close ($ch); echo "Result: " . $result; } 当我通过 Mercadolibre 的消息系统发送附件时,它对我有用。 答案https://stackoverflow.com/a/35227055/7656744 $target_url = "http://server:port/xxxxx.php"; $fname = 'file.txt'; $cfile = new CURLFile(realpath($fname)); $post = array ( 'file' => $cfile ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $target_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data')); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result = curl_exec ($ch); if ($result === FALSE) { echo "Error sending" . $fname . " " . curl_error($ch); curl_close ($ch); }else{ curl_close ($ch); echo "Result: " . $result; } 过程方法中的cURL文件对象: $file = curl_file_create('full path/filename','extension','filename'); Oop 方法中的 cURL 文件对象: $file = new CURLFile('full path/filename','extension','filename'); $data = array('file' => $file); $curl = curl_init(); //curl_setopt ... curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $response = curl_exec($curl); curl_close($curl); 我们可以通过curl请求上传图像文件,将其转换为base64字符串。因此在post中我们将发送文件字符串,然后将其隐藏在图像中。 function covertImageInBase64() { var imageFile = document.getElementById("imageFile").files; if (imageFile.length > 0) { var imageFileUpload = imageFile[0]; var readFile = new FileReader(); readFile.onload = function(fileLoadedEvent) { var base64image = document.getElementById("image"); base64image.value = fileLoadedEvent.target.result; }; readFile.readAsDataURL(imageFileUpload); } } 然后在curl请求中发送它 if(isset($_POST['image'])){ $curlUrl='localhost/curlfile.php'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $curlUrl); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS, 'image='.$_POST['image']); $result = curl_exec($ch); curl_close($ch); } 请参阅此处http://technoblogs.co.in/blog/How-to-upload-an-image-by-using-php-curl-request/118 这是我的解决方案,我读了很多帖子,它们真的很有帮助,最后我用 cUrl 和 Php 为小文件构建了代码,我认为它非常有用。 public function postFile() { $file_url = "test.txt"; //here is the file route, in this case is on same directory but you can set URL too like "http://examplewebsite.com/test.txt" $eol = "\r\n"; //default line-break for mime type $BOUNDARY = md5(time()); //random boundaryid, is a separator for each param on my post curl function $BODY=""; //init my curl body $BODY.= '--'.$BOUNDARY. $eol; //start param header $BODY .= 'Content-Disposition: form-data; name="sometext"' . $eol . $eol; // last Content with 2 $eol, in this case is only 1 content. $BODY .= "Some Data" . $eol;//param data in this case is a simple post data and 1 $eol for the end of the data $BODY.= '--'.$BOUNDARY. $eol; // start 2nd param, $BODY.= 'Content-Disposition: form-data; name="somefile"; filename="test.txt"'. $eol ; //first Content data for post file, remember you only put 1 when you are going to add more Contents, and 2 on the last, to close the Content Instance $BODY.= 'Content-Type: application/octet-stream' . $eol; //Same before row $BODY.= 'Content-Transfer-Encoding: base64' . $eol . $eol; // we put the last Content and 2 $eol, $BODY.= chunk_split(base64_encode(file_get_contents($file_url))) . $eol; // we write the Base64 File Content and the $eol to finish the data, $BODY.= '--'.$BOUNDARY .'--' . $eol. $eol; // we close the param and the post width "--" and 2 $eol at the end of our boundary header. $ch = curl_init(); //init curl curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X_PARAM_TOKEN : 71e2cb8b-42b7-4bf0-b2e8-53fbd2f578f9' //custom header for my api validation you can get it from $_SERVER["HTTP_X_PARAM_TOKEN"] variable ,"Content-Type: multipart/form-data; boundary=".$BOUNDARY) //setting our mime type for make it work on $_FILE variable ); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/1.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'); //setting our user agent curl_setopt($ch, CURLOPT_URL, "api.endpoint.post"); //setting our api post url curl_setopt($ch, CURLOPT_COOKIEJAR, $BOUNDARY.'.txt'); //saving cookies just in case we want curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // call return content curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); navigate the endpoint curl_setopt($ch, CURLOPT_POST, true); //set as post curl_setopt($ch, CURLOPT_POSTFIELDS, $BODY); // set our $BODY $response = curl_exec($ch); // start curl navigation print_r($response); //print response } 有了这个,我们应该在“api.endpoint.post”上发布以下变量 您可以使用此脚本轻松进行测试,并且您应该在最后一行的函数 postFile() 上收到此调试信息 print_r($响应); //打印响应 public function getPostFile() { echo "\n\n_SERVER\n"; echo "<pre>"; print_r($_SERVER['HTTP_X_PARAM_TOKEN']); echo "/<pre>"; echo "_POST\n"; echo "<pre>"; print_r($_POST['sometext']); echo "/<pre>"; echo "_FILES\n"; echo "<pre>"; print_r($_FILEST['somefile']); echo "/<pre>"; } 在这里,它应该工作得很好,可能是更好的解决方案,但这确实有效,并且对于理解边界和多部分/来自数据 mime 如何在 php 和curl 库上工作非常有帮助, 我最诚挚的问候, 我对我的英语表示歉意,但这不是我的母语。

回答 8 投票 0

EasyPHP 上的激活 Curl

取消注释 php.ini 中的curl-modul后,出现以下错误: PHP 警告:PHP 启动:无法加载动态库 'C:\Program Files (x86)\EasyPHP-Devserver-16.1 ds-binaries\...

回答 6 投票 0

curl 身份验证失败,在浏览器中工作

我正在使用 HTML 登录表单来访问应用程序。这在浏览器中有效,但是当我尝试使用curl复制时,我得到“身份验证失败,用户名/密码错误”。我只有李...

回答 1 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.