Path: API › 网站管理

`POST /site`

为网站设置基于 HTTP Basic Auth 的密码访问保护。

## Request body

_Required._

- `action263.request_time` (string, required) — Unix 时间戳。
- `action263.request_token` (string, required) — 按 API 概览生成的签名。
- `action263.action` (string, required) — 具体操作名称。
  - one of `"SetHasPwd"`
- `action263.id` (integer, required) — 网站 ID
- `action263.username` (string, required) — 访问用户名
- `action263.password` (string, required) — 密码（**不超过 8 位**）

## Example request

```text
{
  "request_time": "string",
  "request_token": "string",
  "action": "SetHasPwd",
  "id": 0,
  "username": "string",
  "password": "string"
}
```

## Code samples

### cURL（填写面板地址与签名）

```curl
curl --request POST \
  --url "https://your-panel.example.com:8888/site" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "request_time=<Unix时间戳>" \
  --data-urlencode "request_token=<按 API 概览生成的签名>" \
  --data-urlencode "action=SetHasPwd" \
  --data-urlencode "id=<id>" \
  --data-urlencode "username=<username>" \
  --data-urlencode "password=<password>"
```

## Responses

### default

接口响应，业务状态见下方详细说明。

#### Example

```json
{
  "status": true,
  "msg": "设置成功"
}
```

- `action263.response.default.status` (boolean, optional) — `true` 表示设置成功
- `action263.response.default.msg` (string, optional) — 提示信息


## SetHasPwd

为网站设置基于 HTTP Basic Auth 的密码访问保护。

- **路由**：`POST /site`
- **action**：`SetHasPwd`

## 输入参数

| 参数名称 | 必选 | 类型 | 描述 |
|----------|------|------|------|
| action | 是 | String | 固定值 `SetHasPwd` |
| id | 是 | Integer | 网站 ID |
| username | 是 | String | 访问用户名 |
| password | 是 | String | 密码（**不超过 8 位**） |

> 密码限制 8 位，超过部分无法验证。

## 相关接口

- [GetHasPwd](/api/site/gethaspwd) — 查看密码保护状态
- [CloseHasPwd](/api/site/gethaspwd) — 关闭密码保护

## 输出参数

| 参数名称 | 类型 | 描述 |
|----------|------|------|
| status | Boolean | `true` 表示设置成功 |
| msg | String | 提示信息 |

## 示例

### 请求

```
POST /site HTTP/1.1
Content-Type: application/x-www-form-urlencoded

action=SetHasPwd&id=1&username=admin&password=Test2024
```

### 响应

```json
{"status": true, "msg": "设置成功"}
```

