サイト http://example.com
ユーザー scott
パスワード tiger123
のダイジェスト認証のページへのアクセス方法です。
#
curl --digest --user "scott:tiger123" "http://example.com"
#
# ! /usr/bin/php
<?php
$ch = curl_init("http://example.com");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_USERPWD, "scott:tiger123");
$response = curl_exec($ch);
curl_close($ch);
?>
# ! /usr/bin/python
# -*- coding: utf-8 -*-
#
# Sep/24/2017
# ----------------------------------------------------------------
import sys
import requests
from requests.auth import HTTPDigestAuth
#
# ----------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
#
url="http://example.com"
user="scott"
password="tiger123"
rr=requests.get(url, auth=HTTPDigestAuth(user,password))
print(rr.status_code)
print(rr.text)
#
sys.stderr.write("*** 終了 ***\n")
# ----------------------------------------------------------------