[英]I am getting NULL data in response to cURL request
我正在執行cURL請求以使用api來獲取信息,但是當我使用json_decode時,它沒有提供任何信息,而是返回NULL值。 請通過這些行-
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,"http://mkp.gem.gov.in/oem-cartridge/samsung-111s-toner-rst/p-5116877-68482402616-cat.html");
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
這是使用API進行cURL請求和獲取信息的正確方法,還是建議我該如何做,因為我是本主題的新手。
您的以下代碼行
$result=curl_exec($ch);
返回301永久移動
由於您的網址僅使用HTTP http://mkp.gem.gov.in/oem-cartridge/samsung-111s-toner-rst/p-5116877-68482402616-cat.htm
但是此站點在HTTPS上運行,並且服務器已設置為強制/僅將此HTTP URL重定向到HTTPS,即https://mkp.gem.gov.in/oem-cartridge/samsung-111s-toner-rst/p-5116877-68482402616-cat.html
您可以將網址更改為https,也可以使用將true重定向設為true
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirect if any
但仍然呈現HTML而不是JSON。
但是在您的評論中,您說此相同的URL正在與節點一起使用,在這種情況下,請交叉檢查您的URL或嘗試使用POSTMAN發出相同的請求,然后查看顯示的內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.