I am very new to PHP(Laravel) and got some project. This is the explanation:
- One device exists someplace and it gathers some data.
- My project needs to log in to the device and need to get data by JSON file.
I used this code for that work:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url.0.json");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$response = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
$code = -1;
if (!$errno) $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
It returns 302 found error so I added this line of code:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
After that, I got 200 code but the response is HTML code for the login page.(Not JSON)
When I copy and paste the URL("$url.0.json") in the web browser, it redirects to the login page
I think the login cannot work successfully.
Please give me some advice. I appreciate it in advance