0
我想通過POST發送curl數據。PHP curl post解析錯誤
這裏是我做了什麼
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://lc-api.sdl.com/translate");
$headers = array();
$headers[] = 'Content-type:application/json';
$headers[] = 'Authorization:LC apiKey=QidCWRGQ%2BHsdzGE6rrBgiw%3D%3D';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"text=Bonjour&from=fra&to=eng"); //Post Fields
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
我得到指示
Error parsing json at column:6 line:1 offset:-1
這裏的錯誤是工作捲曲請求
curl -X POST -H "Content-type: application/json" -H "Authorization: LC apiKey=QidCWRGQ%2BHsdzGE6rrBgiw%3D%3D" -d '{"text":"Bonjour", "from" : "fra", "to" : "eng"}' https://lc-api.sdl.com/translate
我收到了同樣的錯誤,即使我改變了它 – user2800040
我'{ 「partialTranslation」:假 「從」:「FRA 「,」to「:」eng「,」wordCount「:1,」charCount「:7,」translation「:」Hello「}'結果。這是根據您的要求得出的結果嗎?清除瀏覽器緩存,然後檢查。 – AnkiiG
是啊ankit這是所需的結果 – user2800040