调用CreatePtsScene接口创建一个PTS场景。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
Action String CreatePtsScene

系统规定参数。取值:CreatePtsScene

Scene String {"loadConfig":{"agentCount":1,"apiLoadConfigList":[{"rpsBegin":10,"rpsLimit":100}],"configuration":{"allRpsBegin":10,"allRpsLimit":100},"maxRunningTime":1,"testMode":"tps_mode"},"relationList":[{"apiList":[{"apiName":"链路1的第一个API","body":{"bodyValue":"{\"key1\":\"111\",\"key2\":\"222\"}","contentType":"application/x-www-form-urlencoded"},"checkPointList":[{"checkPoint":"userId","checkType":"EXPORTED_PARAM","expectValue":"111","operator":"ctn"}],"exportList":[{"exportName":"userId","exportType":"STATUS_CODE"}],"headerList":[{"headerName":"userName","headerValue":"张三"}],"method":"GET","url":"https://www.xxx.com"}],"fileParameterExplainList":[{"baseFile":true,"cycleOnce":false,"fileParamName":"city,name"}],"relationName":"链路1"}],"sceneName":"xing-测试OpenAPI-1"}

场景信息。更多信息,请参见参数说明

返回数据

名称 类型 示例值 描述
SceneId String SDR3CX

创建成功的场景ID。

RequestId String 4F7D2CE0-AE4C-4143-955A-8E4595AF86A6

请求ID。

Message String

错误提示信息,如成功则为空。

HttpStatusCode Integer 200

HTTP状态码。

Code String 200

系统状态码。

Success Boolean true

是否成功。

  • true:成功
  • false:失败

示例

请求示例

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.pts.model.v20201020.CreatePtsSceneRequest;
import com.aliyuncs.pts.model.v20201020.CreatePtsSceneResponse;
import com.taobao.api.entity.pts.scene.*;

import java.util.ArrayList;
import java.util.List;

public class CreatePtsScene {

    private String accessKeyId = "<AccessKey>";
    private String accessSecret = "<AccessSecret>";

    public static void main(String[] args) {
        String sceneId = new CreatePtsScene().createPtsScene();
        System.out.println("sceneId:" + sceneId);
    }

    public String createPtsScene() {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
        CreatePtsSceneRequest request = new CreatePtsSceneRequest();
        request.setScene(getScene());
        String sceneId = null;
        try {
            CreatePtsSceneResponse response = client.getAcsResponse(request);
            if (response.getSuccess()) {
                sceneId = response.getSceneId();
            } else {
                System.out.println("create scene fail message:" + response.getMessage());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
        return sceneId;
    }

    public String getScene() {
        Scene scene = new Scene();
        scene.setSceneName("场景名");

        // 场景链路配置。
        List<Relation> relationList = new ArrayList<>();
        Relation relation = new Relation();
        relation.setRelationName("第一个链路");
        List<Api> apiList = new ArrayList<>();
        Api api = new Api();
        api.setApiName("第一个API");
        api.setUrl("https://www.xxx.com");
        api.setMethod(Method.GET);
        apiList.add(api);
        relation.setApiList(apiList);
        relationList.add(relation);
        scene.setRelationList(relationList);

        // 场景施压配置。
        LoadConfig loadConfig = new LoadConfig();
        loadConfig.setTestMode("tps_mode");
        Configuration configuration = new Configuration();
        configuration.setAllRpsBegin(10);
        configuration.setAllRpsLimit(100);
        loadConfig.setConfiguration(configuration);
        loadConfig.setMaxRunningTime(2);
        scene.setLoadConfig(loadConfig);

        return JSONObject.toJSONString(scene);
    }
}

正常返回示例

XML格式

HTTP/1.1 200 OK
Content-Type:application/xml

<CreatePtsSceneResponse>
    <SceneId>SDR3CX</SceneId>
    <RequestId>4F7D2CE0-AE4C-4143-955A-8E4595AF86A6</RequestId>
    <Message/>
    <HttpStatusCode>200</HttpStatusCode>
    <Code>200</Code>
    <Success>true</Success>
</CreatePtsSceneResponse>

JSON格式

HTTP/1.1 200 OK
Content-Type:application/json

{
  "SceneId" : "SDR3CX",
  "RequestId" : "4F7D2CE0-AE4C-4143-955A-8E4595AF86A6",
  "Message" : "",
  "HttpStatusCode" : 200,
  "Code" : "200",
  "Success" : true
}

错误码

访问错误中心查看更多错误码。