[comment]: # translation:outdated

[comment]: # ({3c277f74-3c277f74})

# 创建

[comment]: # ({/3c277f74-3c277f74})

[comment]: # ({2e029999-c4bddb28})

### 描述

`object httptest.create(object/array webScenarios)`

此方法允许创建新的Web场景。

::: noteclassic
创建一个Web场景将自动创建一组[web monitoring items](/manual/web_monitoring/items)。
:::

::: noteclassic
此方法只有*Admin(管理员)* 和 *Super admin(超级管理员)* 用户可用。可以在用户角色设置中撤销调用该方法的权限。更多信息请查看 [User roles](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/2e029999-c4bddb28})

[comment]: # ({72a782af-5bd5a38b})

### 参数

`(object/array)` 需要创建的Web场景。

除了 [standard web scenario properties](object#web场景)，此方法接受如下参数。

|参数|[类型](/manual/api/reference_commentary#数据类型)|描述|
|---------|---------------------------------------------------|-----------|
|**steps**<br>(必填)|array|Web场景[steps](/manual/api/reference/httptest/object#场景步骤)。|
|tags|array|Web场景[tags](/manual/api/reference/httptest/object#web场景标签)。|

[comment]: # ({/72a782af-5bd5a38b})

[comment]: # ({0f4da548-0f4da548})

### 返回值

`(object)` 返回一个包含已创建Web场景ID的对象，ID在`httptestids`属性下。返回的IDs的顺序和传递的Web场景的顺序相匹配。

[comment]: # ({/0f4da548-0f4da548})

[comment]: # ({b41637d2-b41637d2})

### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({d524a2a7-0b10bb11})
#### 创建一个Web场景

创建一个Web场景用于监控公司主页。此场景具有两个步骤，检查主页和“关于”页，并保证它们返回HTTP状态码200。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "httptest.create",
    "params": {
        "name": "Homepage check",
        "hostid": "10085",
        "steps": [
            {
                "name": "Homepage",
                "url": "http://example.com",
                "status_codes": "200",
                "no": 1
            },
            {
                "name": "Homepage / About",
                "url": "http://example.com/about",
                "status_codes": "200",
                "no": 2
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "httptestids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/d524a2a7-0b10bb11})

[comment]: # ({e8ca015f-e8ca015f})

### 参见

-   [Scenario step](object#场景步骤)

[comment]: # ({/e8ca015f-e8ca015f})

[comment]: # ({6b938292-6b938292})

### 来源

CHttpTest::create() in *ui/include/classes/api/services/CHttpTest.php*.

[comment]: # ({/6b938292-6b938292})
