get - 当 url 是字符串变量时,如何在一个 GET 请求中传递 pathParam、queryParam 和 headers
问题描述
第一个问题:我有一个 API GET 请求,其中包含路径参数、查询参数和标头,我想将我的请求 url 作为字符串变量,我该如何实现?
第二个问题:如何将 pathParams 传递给字符串变量?我研究过如何传递路径参数,但是所有的例子都是get(" http://some_url/ {path}"),我想把url作为一个String。
像 String url = " http://my/request/url ",
如何使用 url+{id}?没有得到http字符串?
given()
.contentType(ContentTypeJSON).
with()
.pathParams("id", "1").
when()
.get("http://my/request/url/{id}").
then()
.assertThat().
.statusLine("HTTP/1.1 200 OK");
解决方案
避免返工的简单方法是使用以下代码。
/*
* We can parameterize it using baseURI and basePath and send a request to get a customer using ID
*/
RestAssured.baseURI = "http://parabank.parasoft.com/";
RestAssured.basePath = "parabank/services/bank/customers";
//also we can use a path parameter for the same request
given().contentType(ContentType.JSON).pathParam("customers", "12212").when().get("{customers}/").then().statusCode(200).log().all();
推荐阅读
- amazon-web-services - S3 存储桶的公共读取访问权限不起作用
- react-native - TypeError:未定义不是对象(评估'_react.default.PropTypes.string')
- python - pyst2(python星号库)中ARGS的值应该是什么?
- swift - RealityKit – 从 Web URL 资源加载 ModelEntity
- java - 以快速的方式将 assertXY 语句从 JUnit4 迁移到 Junit5?
- android - 连接到 Android 10 上的接入点(无互联网)
- flutter - Flutter DropdownMenu未显示所选项目
- python - 为什么我们使用分类数据类型和 cat.codes?
- r - 反转数据框中的列和行
- laravel - 使用 updateExistingPivot 更新数据透视表 - Laravel 8