2017-09-14 38 views
-4

我在cURL中得到了這段代碼。我想用PHP來轉換或執行它。在php中轉換curl

curl -X POST -H "auth_id: {{market_id}}" -H "auth_token: {{auth_token}}" -H "Content-Type: multipart/form-data;" -F "campaign_slug={{campaign_slug}}" -F "[email protected]{{file.csv}}" 'https://{{market_subdomain}}.co-buying.com/api/potential_campaign_signups/upload' 

你能告訴我該怎麼做嗎?

謝謝 巴斯蒂安

+1

你到目前爲止嘗試過什麼? – OptimusCrime

+1

請相信搜索的力量。 – siniradam

+0

這個問題違反了指導原則,因爲它過於寬泛。 – catbadger

回答

-2

你可以使用一些在線轉換器。像 https://incarnate.github.io/curl-to-php/ 要自己寫這個網址可能是你的指南; http://code.stephenmorley.org/php/sending-files-using-curl/

還請全覆蓋curl parameters

如果不能成功,你可能想嘗試

exec($curlCommand,$result); 

也請閱讀EXEC documentation

+0

謝謝,但我已經嘗試過了。它並沒有考慮到所有信息,比如帖子的csv文件。 – Bastien

+0

然後請檢查這一個:https://stackoverflow.com/questions/1939609/convert-command-line-curl-to-php-curl – siniradam

-1

您可以使用curl-to-php

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, "https://{{market_subdomain}}.co-buying.com/api/potential_campaign_signups/upload"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POST, 1); 

$headers = array(); 
$headers[] = "Auth_id: {{market_id}}"; 
$headers[] = "Auth_token: {{auth_token}}"; 
$headers[] = "Content-Type: multipart/form-data;"; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

$result = curl_exec($ch); 
if (curl_errno($ch)) { 
    echo 'Error:' . curl_error($ch); 
} 
curl_close ($ch);