LoginSignup
6
8

More than 5 years have passed since last update.

Digest 認証のクライアント curl,php,python3

Posted at

サイト 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")
# ----------------------------------------------------------------
6
8
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
6
8