将命令行 cURL 转换为 PHP cURL

编程入门 行业动态 更新时间:2024-10-27 21:24:24
本文介绍了将命令行 cURL 转换为 PHP cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我以前从未做过任何卷曲,所以需要一些帮助.我试图从示例中解决这个问题,但无法理解它!

I've never done any curl before so am in need of some help. I've tried to work this out from examples but cannot get my head around it!

我有一个 curl 命令,我可以从 linux(ubuntu) 命令行成功运行该命令,该命令行通过 api 将文件放入 wiki.

I have a curl command that I can successfully run from a linux(ubuntu) command line that puts a file to a wiki through an api.

我需要将此 curl 命令合并到我正在构建的 PHP 脚本中.

I would need to incorporate this curl command in a PHP script I'm building.

如何翻译此 curl 命令,使其在 PHP 脚本中工作?

How can I translate this curl command so that it works in a PHP script?

curl -b cookie.txt -X PUT --data-binary "@test.png" -H "Content-Type: image/png" "hostname/@api/deki/pages/=TestPage/files/=test.png" -0

cookie.txt 包含身份验证,但我将其以明文形式放入脚本中没有问题,因为这将仅由我运行.

cookie.txt contains the authentication but I don't have a problem putting this in clear text in the script as this will be run by me only.

@test.png 必须是 $filename 等变量

@test.png must be a variable such as $filename

hostname/@api/deki/pages/=TestPage/files/= 必须是一个变量,例如 $pageurl

hostname/@api/deki/pages/=TestPage/files/= must be a variable such as $pageurl

感谢您的帮助.

推荐答案

一个起点:

<?php $pageurl = "hostname/@api/deki/pages/=TestPage/files/="; $filename = "test.png"; $theurl = $pageurl . $filename; $ch = curl_init($theurl); curl_setopt($ch, CURLOPT_COOKIE, ...); // -b curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -X curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -H curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0 ... ?>

另见:www.php/manual/en/function.curl-setopt.php

更多推荐

将命令行 cURL 转换为 PHP cURL

本文发布于:2023-06-05 01:24:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   命令行   cURL   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!