我想向API发送表单数据,该API必须提供密钥和配置文件,然后通过邮寄请求发送数据后,我必须发送get请求以获取信息
这是他们提供的发布功能:
curl -k -X POST --header "X-API-KEY:TOKEN" -F "profile=B2B" -F
"data_file=@/var/tmp/testfile.csv" -F "md5=ae0eca4f5671cbdc19340a1df2567611"
https://api.cloudHygiene.com/task/run
这是他们提供的get函数:
curl -k -X GET --header "X-API-KEY:TOKEN"
https://api.cloudhygiene.com/task/get_file?
package_name=hWviW2hLui_1477652942&f
ilename=_report.xls
答案 0 :(得分:0)
您是否在问如何在PHP中运行cURL命令?如果是这样,这是PHP中cURL请求的第一部分:
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudHygiene.com/task/run");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "X-Api-Key: TOKEN";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
这是第二部分:
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudhygiene.com/task/get_file?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "X-Api-Key: TOKEN";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
同样,我只是猜测您是在要求在PHP中运行cURL请求。如果没有,建议改写您的问题并提供更多详细信息。