加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

CLI CURL – > PHP CURL

发布时间:2020-12-14 02:27:15 所属栏目:Linux 来源:网络整理
导读:如何翻译此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
如何翻译此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,array(
        'Content-Type: application/atom+xml'
    ));
curl_setopt($ch,'http://siteurl.com');
curl_setopt($ch,file_get_contents($filename));  
curl_exec($ch);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读