Laravel Http Client 的 User-Agent 头部是 -A。

huangapple go评论64阅读模式
英文:

Laravel Http Client User-Agent header as -A

问题

如何使用特殊的curl参数-A而不是-H来传递User-Agent头?

这段代码使用-H参数添加User-Agent头:

Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0'])

这段代码没有效果:

Http::beforeSending(function(Illuminate\Http\Client\Request $request) {
    $request->toPsrRequest()
        ->withHeader('User-Agent', 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0');
});
英文:

How can I pass User-Agent header with a especial curl parameter -A, not -H?

Laravel Http Client 的 User-Agent 头部是 -A。

This code adds User-Agent with -H parameter, not -A:

Http::withHeaders(['User-Agent' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0'])

This code has no effect:

Http::beforeSending(function(Illuminate\Http\Client\Request $request) {
    $request->toPsrRequest()
        ->withHeader('User-Agent', 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0');
});

答案1

得分: 1

Http::withOptions([
    'CURLOPT_USERAGENT' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0',
]);
英文:

What about

Http::withOptions([
    'CURLOPT_USERAGENT' => 'Mozilla/5.0 (Android 13; Mobile; rv:109.0) Gecko/111.0 Firefox/111.0',
]);

huangapple
  • 本文由 发表于 2023年7月18日 01:42:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定