4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GuzzleでBASIC認証のページにアクセスする

Posted at

概要

Guzzleを使って、Basic認証がかかったページにアクセスする方法です。

完全に備忘録ですが・・


$client = new Clinet();
$request = $client->get('http://example.com');
$request->setAuth('{ユーザ名}', '{パスワード}');
$request->send();

で、OK。
getメソッドの第二引数に$headersってのを渡せるので、↓でも行けそうな気がしたけどなぜか上手く行かなかった。

$request = $client->get('http://example.com', array('auth' => array('{ユーザ名}', '{パスワード}'));
``
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?