.htaccess 密码验证但允许发布请求

标签 .htaccess post curl

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

当前的.htaccess:

#AuthUserFile /home/domain/.htpasswds/.htpasswd
#AuthType Basic
#AuthName "Protected Domain"
#Require valid-user

PHP curl 请求

    $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);

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.

编辑:我关心的不是安全性,而是阻止人们浏览网站。

最佳答案

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

关于.htaccess 密码验证但允许发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16508696/

相关文章:

.htaccess - Webkit 浏览器(Chrome、Safari)加载从 .htaccess 重定向的页面两次!

wordpress - 漂亮的 url 与 .htaccess?

php - SEO 友好的 .htaccess 总是引导我到主页

swift - Alamofire + 光泽 : nested JSON array not working

java - 如何解析 <*> 的证书与任何主题备用名称 : [*]? 不匹配

javascript - 利用浏览器缓存 |修改 .htaccess 文件 | - 不适用于 javascript 文件

php - Codeigniter $this->input->post 始终为 FALSE

ubuntu - 如何连接到安装在 Ubuntu 16 上的远程 ElasticSearch 服务器?

curl - 相同的 WSAPI v2.0 安全 key 在 REST 客户端中有效,但在与 curl 一起使用时会产生无效 key 错误

php - 处理数组字段发布数据