Larevel HTTP客户端错误403生产

发布于 2025-01-29 12:48:56 字数 733 浏览 3 评论 0原文

我正在研究一个致电电子商务网站以获取一些信息并对其进行分析的项目。

我编写了以下代码以获取信息:

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);
     }
}

问题:

该代码在Localhost上工作,但是将其部署到服务器时返回403错误。

附加信息:

  • 外部网站基于KSA(不知道服务器在哪里),
  • 当我将URL复制并粘贴到浏览器中时,它返回200
  • 中在我们的共享托管服务器上工作
  • 该代码在我们 代码正在ksa中的localhost工作。
  • 代码在VPS服务器上不起作用是Frankfort

我尝试使用guzzlehttp \ client并添加一些标题,但这也不起作用

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玻璃人 2025-02-05 12:48:56

由于声誉较低,我无法发表评论,但是我需要查看日志。检查您的服务器,让我知道它在说什么。

这可能从多种原因范围内,我遇到了“丢失密钥”的问题(php工匠密钥:生成

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)

夕色琉璃 2025-02-05 12:48:56

也许有关他们可能不喜欢从服务器作为卷发发送的问题,它们允许在Local主机上,但有时会根据服务器的请求将其阻止。

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
}

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
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文