[英]convert POST cURL PHP request to cURL command line using array parameters
[英]using curl without command line, but with php for a post method
我需要從php執行http post / curl查詢,並將結果存儲在jsor變量中。
在我的文檔中,它說有兩種方法:
示例POST:
curl -X POST“ http://developer.echonest.com/api/v4/track/upload ” -d“ api_key = xxxxxx&url = http://example.com/audio.mp3 ”
但是如何在php中實現呢? 我沒有任何線索。 從我的閱讀中,我不認為curl_init方法會像在php網站上描述的那樣起作用,因為它不是post方法:
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
我歡迎任何指示如何進行。 謝謝。
這樣呢
$post = array(
"url"=>"path/to/file/example_homepage.txt",
"api_key"=>"xxxxxx"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "http://developer.echonest.com/api/v4/track/upload");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
還有其他選項,具體取決於您可能需要的情況,SSL,Cookie,用戶代理等。 這是php參考的鏈接!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.