英文:
create a GET request with RequestSpecBuilder
问题
我尝试过查询参数和路径参数,但是出现了错误:“未定义的路径参数为:job_id”。
我猜这是因为URI的格式出错了。
builder.addQueryParams(queryParams);
return getAPIResponse();
期望的格式是 https://api.themoviedb.org/4/list/{job_id}
实际的格式是 https://api.themoviedb.org/4/list/?job_id={job_id}
如何才能构建出期望格式的URI呢?
英文:
I have tried query Params and path Params but it is giving error Undefined path parameters are: job_id
I guess it is because because URI is ending up in wrong format.
builder.addQueryParams(queryParams);
return getAPIResponse();
Expected Format is https://api.themoviedb.org/4/list/{job_id}
Actual Format is https://api.themoviedb.org/4/list/?job_id={job_id}
How can build the URI in expected format?
答案1
得分: 0
预期的是一个路径参数 https://api.themoviedb.org/4/list/{job_id}
,但您却将其添加为一个查询参数 addQueryParams
RequestSpecBuilder builder = new RequestSpecBuilder();
builder.addPathParam("job_id", "abc");
RequestSpecification requestSpec = builder.build();
given().log().all().spec(requestSpec).when().get("https://api.themoviedb.org/4/list/{job_id}");
英文:
The expected is a pathparam https://api.themoviedb.org/4/list/{job_id}
but you are adding it as a queryParam addQueryParams
RequestSpecBuilder builder = new RequestSpecBuilder();
builder.addPathParam("job_id", "abc");
RequestSpecification requestSpec = builder.build();
given().log().all().spec(requestSpec).when().get("https://api.themoviedb.org/4/list/{job_id}");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论