-1
我的目標是在我的工作上連接一個專用Web服務。 即時通訊嘗試連接,但是當我將Content-Type設置爲application/json時,它失敗並返回null,有人可以提供幫助嗎? 這是我的代碼:curl無法設置標題應用程序/ json php
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8')
);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
$fp = fopen(WAREHOUSE . '/errorlogc.txt', 'w');
curl_setopt($curl, CURLOPT_STDERR, $fp);
$json_response = curl_exec($curl);
當我執行這個代碼,它將失敗並返回null並沒有更多的信息,甚至是我設置日誌顯示它的我什麼。
「當我設置的Content-Type爲application/JSON」 - 我沒有看到任何企圖做,在你的代碼共享。 – Quentin
...並且你有很多未定義的變量。你[mcve]確實需要完成。 – Quentin