2019-02-08 05:43
浏览 245

如何使用PHP Curl或Guzzel Client使用动态用户代理标头

I am new to PHP and trying to call a REST Service. I could do that using either Curl or Guzzle Client in PHP. Later I am calling this from Mozilla and Chrome Browser.

The problem is Guzzle and Curl are not forwarding the actual User-Agent header as Request Header to the backend services.

The default Guzzle User-Agent header is Guzzle/ver curl/ver PHP/ver

I know we can add custom/hardcoded headers in both Curl and Guzzle. But I dont want to hardcode.

require './vendor/autoload.php';
$client = new GuzzleHttp\Client();
$res = $client->request('GET', '');
$data = json_decode($res->getBody(), true); 
//echo  $res->getBody()  

    <p>Body  is  <?php echo  $res->getBody() ?> </p>

When I call the PHP service from either Chrome/Mozilla/Mobile/Safari, I want the respective user-agent headers to be sent as request headers to backend services.

If there a way to do this in any way?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题