在 android 中构建 URL 的最佳实践
Best Practice to build URL in android
在 Android 中构建 Http Uri 的最佳做法是什么。我想使用 Uri.Builder 构建 url.
我想创建一个 class,它将 return 所有 Http url 包括参数。
我在下面的 link 中检查了 Uri.Builder,这给出了在 get 请求的情况下使用的想法,但如何在 post 请求中使用 Uri.Builder 的力量.
Use URI builder in Android or create URL with variables
总而言之,我要求通过利用 Uri.Builder
的力量构建 Http Urls(Get 和 post 两者)的最佳实践
GET 和 POST url 之间没有区别。 http 请求方法会不同,但 URI 可以相同。
例如检查此 one and this one。他们都使用相同的资源 Url 但方法不同。
Uri.Builder用于创建Uri,GET和POST都可以使用它。所以要构建 Uri https://api.twitter.com/1.1/account/settings.json
(来自上面的示例)我可以使用此代码
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("api.twitter.com")
.appendPath("1.1")
.appendPath("account")
.appendPath("settings.json");
Uri uri = builder.build();
我认为您正在搜索类似 HttpRequest.Builder 的内容,但我不知道。您仍然可以使用第三方库,例如 retrofit.
在 Android 中构建 Http Uri 的最佳做法是什么。我想使用 Uri.Builder 构建 url.
我想创建一个 class,它将 return 所有 Http url 包括参数。
我在下面的 link 中检查了 Uri.Builder,这给出了在 get 请求的情况下使用的想法,但如何在 post 请求中使用 Uri.Builder 的力量.
Use URI builder in Android or create URL with variables
总而言之,我要求通过利用 Uri.Builder
的力量构建 Http Urls(Get 和 post 两者)的最佳实践GET 和 POST url 之间没有区别。 http 请求方法会不同,但 URI 可以相同。
例如检查此 one and this one。他们都使用相同的资源 Url 但方法不同。
Uri.Builder用于创建Uri,GET和POST都可以使用它。所以要构建 Uri https://api.twitter.com/1.1/account/settings.json
(来自上面的示例)我可以使用此代码
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("api.twitter.com")
.appendPath("1.1")
.appendPath("account")
.appendPath("settings.json");
Uri uri = builder.build();
我认为您正在搜索类似 HttpRequest.Builder 的内容,但我不知道。您仍然可以使用第三方库,例如 retrofit.