--- title: WWW-Authenticate slug: Web/HTTP/Headers/WWW-Authenticate tags: - HTTP - HTTP Header - Reference - Response Header - header translation_of: Web/HTTP/Headers/WWW-Authenticate --- <div>{{HTTPSidebar}}</div> <p> HTTP <strong><code>WWW-Authenticate</code></strong> 响应头定义了使用何种验证方式去获取对资源的连接。</p> <p><code>WWW-Authenticate</code> header通常会和一个 {{HTTPStatus("401")}} <code>Unauthorized</code> 的响应一同被发送。</p> <table class="properties"> <tbody> <tr> <th scope="row">Header type</th> <td>{{Glossary("Response header")}}</td> </tr> <tr> <th scope="row">{{Glossary("Forbidden header name")}}</th> <td>no</td> </tr> </tbody> </table> <h2 id="语法">语法</h2> <pre class="syntaxbox notranslate">WWW-Authenticate: <type> realm=<realm> </pre> <h2 id="指令">指令</h2> <dl> <dt><type></dt> <dd><a href="/en-US/docs/Web/HTTP/Authentication#Authentication_schemes">Authentication type</a>,一个通用类型 <a href="/en-US/docs/Web/HTTP/Authentication#Basic_authentication_scheme">"Basic"</a>。 IANA 维护了一个 <a href="http://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml">list of Authentication schemes</a>。</dd> <dt>realm=<realm></dt> <dd>一个保护区域的描述。如果未指定realm, 客户端通常显示一个格式化的主机名来替代。</dd> <dt>charset=<charset></dt> <dd>当提交用户名和密码时,告知客户端服务器首选的编码方案。唯一的允许值是不区分大小写的字符串"UTF-8"。这与realm字符串的编码无关。</dd> </dl> <h2 id="示例">示例</h2> <p>通常的, 一个服务器响应包含一个像如下<code>WWW-Authenticate</code>的头信息:</p> <pre class="notranslate">WWW-Authenticate: Basic WWW-Authenticate: Basic realm="Access to the staging site" </pre> <p>作为一个例子,可以查看<a href="/en-US/docs/Web/HTTP/Authentication"> HTTP authentication</a> 页面,了解如何配置Apache和nginx服务器来使用HTTP basic authentication密码保护你的站点。</p> <h2 id="规范">规范</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Title</th> </tr> <tr> <td>{{RFC("7235", "WWW-Authenticate", "4.1")}}</td> <td>HTTP/1.1: Authentication</td> </tr> <tr> <td>{{RFC("7617")}}</td> <td>The 'Basic' HTTP Authentication Scheme</td> </tr> </tbody> </table> <h2 id="另请参阅">另请参阅</h2> <ul> <li><a href="/en-US/docs/Web/HTTP/Authentication">HTTP authentication</a></li> <li>{{HTTPHeader("Authorization")}}</li> <li>{{HTTPHeader("Proxy-Authorization")}}</li> <li>{{HTTPHeader("Proxy-Authenticate")}}</li> <li>{{HTTPStatus("401")}}, {{HTTPStatus("403")}}, {{HTTPStatus("407")}}</li> </ul>