这就是你构建 Uri/Url 的方式吗?
Is this how you build a Uri/Url?
我正在尝试使用 uri Builder 构建 URL 并使用来自不同端点的 Volley 从 json 文件中提取数据。我的 Url 看起来像这样 //http://api.themoviedb.org/3/movie/157336/videos?api_key=###。我不确定我这样做是否正确,因为我收到错误请求 400,所以我怀疑我遗漏了什么。
Intent intent = getIntent();
String movieId = intent.getStringExtra(Constants.MOVIE_ID);
Uri.Builder builder = new Uri.Builder();
builder.scheme("http")
.authority("api.themoviedb.org/3/movies/")
.appendPath(movieId)
.appendPath("videos")
.appendQueryParameter("api_key", BuildConfig.ApiKey);
String myUrl = builder.build().toString();
您的 url 存在多个错误,但只有一个与您构建它的方式有关。
Authority 应该没有任何路径段,这些应该与附加路径一起添加,因为 / 将被编码并且你以这个 url 结尾:
https://api.themoviedb.org%2F3%2Fmovies%2F/157336/videos?api_key=###
所以把这部分分成以下几部分:
.authority("api.themoviedb.org")
.appendPath("3")
.appendPath("movies")
然后有一些关于 tmdb 的细节
首先,您只能通过 https 调用他们的 api,因此将其设置为方案:
builder.scheme("https")
那么你正试图到达一个未定义的端点,如果你查看 https://developers.themoviedb.org/3/movies/get-movie-videos 下的文档,你会注意到你目前正试图到达
/movies/{id}/videos
但终点位于:
/movie/{id}/videos
所以改变:
.appendPath("movies")
与
.appendPath("movie")
现在,如果您注销 myUrl 变量,您应该会看到以下内容 url:
https://api.themoviedb.org/3/movie/157336/videos?api_key=###
哪个是正确的。
我正在尝试使用 uri Builder 构建 URL 并使用来自不同端点的 Volley 从 json 文件中提取数据。我的 Url 看起来像这样 //http://api.themoviedb.org/3/movie/157336/videos?api_key=###。我不确定我这样做是否正确,因为我收到错误请求 400,所以我怀疑我遗漏了什么。
Intent intent = getIntent();
String movieId = intent.getStringExtra(Constants.MOVIE_ID);
Uri.Builder builder = new Uri.Builder();
builder.scheme("http")
.authority("api.themoviedb.org/3/movies/")
.appendPath(movieId)
.appendPath("videos")
.appendQueryParameter("api_key", BuildConfig.ApiKey);
String myUrl = builder.build().toString();
您的 url 存在多个错误,但只有一个与您构建它的方式有关。 Authority 应该没有任何路径段,这些应该与附加路径一起添加,因为 / 将被编码并且你以这个 url 结尾: https://api.themoviedb.org%2F3%2Fmovies%2F/157336/videos?api_key=###
所以把这部分分成以下几部分:
.authority("api.themoviedb.org")
.appendPath("3")
.appendPath("movies")
然后有一些关于 tmdb 的细节 首先,您只能通过 https 调用他们的 api,因此将其设置为方案:
builder.scheme("https")
那么你正试图到达一个未定义的端点,如果你查看 https://developers.themoviedb.org/3/movies/get-movie-videos 下的文档,你会注意到你目前正试图到达
/movies/{id}/videos
但终点位于:
/movie/{id}/videos
所以改变:
.appendPath("movies")
与 .appendPath("movie")
现在,如果您注销 myUrl 变量,您应该会看到以下内容 url:
https://api.themoviedb.org/3/movie/157336/videos?api_key=###
哪个是正确的。