使用RequestSpecBuilder创建一个GET请求。

huangapple go评论62阅读模式
英文:

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}");

huangapple
  • 本文由 发表于 2020年7月27日 14:17:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63109645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定