gpt4 book ai didi

php - CLI CURL -> PHP CURL

转载 作者:搜寻专家 更新时间:2023-10-31 20:51:44 33 4
gpt4 key购买 nike

我如何翻译这个 curl 命令以使其在 PHP 脚本中运行?

curl --request POST --data-binary '@import.xml' --header "Content-Type: application/atom+xml" --header "Content-Length: 378" "http://url.com"

这行不通:

$data = array('file'=>$filename);                    

$headers = array(
'Content-Type: application/atom+xml',
'Content-Length: 378'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'httpL//url.com');
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);

最佳答案

试试这个:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/atom+xml'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'http://siteurl.com');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));
curl_exec($ch);

关于php - CLI CURL -> PHP CURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6749431/

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