.htaccess 密码验证但允许 post 请求

chu*_*Dub 3 .htaccess post curl

我想用密码保护我的域,因为我只是用它来测试脚本,但我需要允许curl HTTP POST 请求。这可能吗?

当前.htaccess:

#AuthUserFile /home/domain/.htpasswds/.htpasswd
#AuthType Basic
#AuthName "Protected Domain"
#Require valid-user
Run Code Online (Sandbox Code Playgroud)

PHP 卷曲请求

    $handle = curl_init('http://wwww.domain.com/cgi/mailScript.php');
    curl_setopt($handle, CURLOPT_POST, 1);
    curl_setopt($handle, CURLOPT_POSTFIELDS, $serial);
    curl_exec($handle);
Run Code Online (Sandbox Code Playgroud)

PHP错误:

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Additionally, a 401 Authorization Required error was encountered while trying to use an ErrorDocument to handle the request.
Run Code Online (Sandbox Code Playgroud)

编辑:我并不担心安全性,而只是担心阻止人们探索该网站。

And*_*olk 5

$username = 'login';
$password = 'pass';
//...
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($handle, CURLOPT_USERPWD, $username . ":" . $password);
curl_exec($handle);
Run Code Online (Sandbox Code Playgroud)