php - 下面 curl 命令的 php curl 版本是什么
问题描述
以下命令的 php curl 版本是什么
curl -X PUT -H 'Content-Type: text/csv' -H 'Accept: application/json' -d @file.csv [URL]
我有以下 php curl 版本,它不起作用
$headers = [
'Content-Type: text/csv',
'Accept: application/json'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filename));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
解决方案
试试下面的代码
$headers = [
'Content-Type: text/csv',
'Accept: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ''.$url'');
curl_setopt($ch, CURLOPT_PUT, 1);
$fp = fopen($file_path, 'r');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response= curl_exec ($ch);
fclose($fp);
推荐阅读
- python - Dataframe 有一列是字典列表,我需要将它们解析为新的列
- django-rest-framework - 自定义序列化程序中未定义 DRF 名称
- javascript - onclick 从数据库重新加载内容
- mysql - MySQL,特定语句中ON和WHERE之间的功能差异
- java - 在 Java 中创建类类型的变量
- c++ - 如何修复“for”循环并没有停止
- haskell - 使用foldl时如何获取列表中元素的索引
- r - 如何更改原子向量以运行 ANOVA?
- python - 在条件下合并来自两个不同数据框的两列,python
- c++ - 在c++中获取命令的stderror和stdout