英文:
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
?
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',
]);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论