我在现在使用基本身份验证保护的服务器上部署了一个 API。
我还有一个脚本在运行 APi 的同一台服务器上运行,它需要调用 API。
脚本:test.php
<?php
$url = 'https://my_site.myapi/account/add/{"account_id":"1234555"}
$username = 'myname';
$password = 'mypassword';
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
curl_close($ch);
当我尝试从浏览器调用 test.php 时:
https://my_site.myapi/test.php
我被提升为用户名和密码。我没有收到错误消息。有任何想法吗?
虚拟主机部分
DocumentRoot /var/www/mysite/web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/api_section_1">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /usr/local/apache/passwd/passwords
</Directory>
Alias /winapi /var/www/another_section/
<Directory "/var/www/another_section">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
AuthType Basic
AuthName "Restricted Access"
AuthUserFile /usr/local/apache/passwd/passwords
</Directory>