I'm working on a project that calls an e-commerce website to get some information and does analysis on them.
I wrote the following code to get the information:
use Illuminate\Support\Facades\Http;
class TheController extends Controller {
public function getProductAndCompetitors() {
public function getInformation() {
$url = 'https://www.noon.com/_svc/catalog/api/v3/search?sku=N29905443A';
$response = HTTP::get($url);
dd($response);
}
}
The problem:
the code is working on localhost but returning 403 error when I deployed it to a server.
Additional information:
- the external website is based in KSA (no idea where the server is)
- when I copy and paste the url in the browser it returns 200
- the code is working on a shared hosting server in US
- the code is working on localhost in KSA
- the code is not working on VPS server is Frankfort
I tried to use GuzzleHttp\Client instead and add some headers but this didn't work as well
CodePudding user response:
I cannot comment due to low reputation, but I need to see the logs. Check your server and let me know what it says.
This could range from a variety of reasons, and I have encountered to be common the issue of the "missing key" (php artisan key:generate
)
CodePudding user response:
maybe issue regarding they might not like request being send from server as curl, they allow it on localhost but they sometimes block it on requests from a server.
try{
$url = 'https://www.noon.com/_svc/catalog/api/v3/search?sku=N29905443A';
$response = Http::withHeaders([
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
])->get($url);
dd($response->body());
} catch(\Illuminate\Http\Client\RequestException $e){
// Log your errors
}