CLI CURL – > PHP CURL

前端之家收集整理的这篇文章主要介绍了CLI CURL – > PHP CURL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何翻译此curl命令以使其在 PHP脚本中工作?
  1. curl --request POST --data-binary '@import.xml' --header "Content-Type: application/atom+xml" --header "Content-Length: 378" "http://url.com"

这不起作用:

  1. $data = array('file'=>$filename);
  2.  
  3. $headers = array(
  4. 'Content-Type: application/atom+xml','Content-Length: 378'
  5. );
  6.  
  7. $ch = curl_init();
  8. curl_setopt($ch,CURLOPT_POST,1);
  9. curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
  10. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  11. curl_setopt($ch,CURLOPT_URL,'httpL//url.com');
  12. curl_setopt($ch,CURLOPT_BINARYTRANSFER,TRUE);
  13. curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
  14. curl_exec($ch);

解决方法

尝试这个:
  1. $ch = curl_init();
  2. curl_setopt($ch,array(
  3. 'Content-Type: application/atom+xml'
  4. ));
  5. curl_setopt($ch,'http://siteurl.com');
  6. curl_setopt($ch,file_get_contents($filename));
  7. curl_exec($ch);

猜你在找的Linux相关文章