我有以下的PHP代碼POST JSON使用PHP捲曲
curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers); curl_setopt($ch, CURLOPT_ENCODING , "gzip"); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path); curl_setopt($ch, CURLOPT_POSTFIELDS, '{"folderId":"1","parameters":{"amount":3,"ascending":false,"offset":0,"sort":"date"}}'); curl_setopt($ch, CURLOPT_POST, 1);
但我不明白爲什麼不工作。我發佈JSON的API說,沒有收到參數。我的代碼有什麼問題嗎?我認爲整個技巧在JSON參數上......我不確定如何發送它們,因爲我通常看不到任何「nave-> value」與http分析器,因爲它通常以簡單的形式出現...只是沒有任何「名稱」的JSON代碼。
什麼是發送的內容類型?你爲什麼不使用'json_encode'? – mario
@mario我試着用curl_setopt($ ch,CURLOPT_HTTPHEADER,array('Content-type:application/json'));並且不工作。默認情況下,我將標題設置爲$ headers = array( 「Expect:」, );我不明白它將如何與json_encode – Ameli
一起工作您將不得不諮詢API維護者。我們只能猜測。 – mario