To create new HttpUrl.Builder instance from existing URL I use HttpUrl.newBuilder(String):
new HttpUrl().build().newBuilder(savedUrl)
where savedUrl is a String containing well-formed URL.
The above fragment crashes in HttpUrl constructor because of scheme is undefined. As a workaround I use existing HttpUrl instance - less than ideal.
The questions are:
Use parse
to create a new builder from an existing well-formed URL string:
HttpUrl.Builder urlBuilder = HttpUrl.parse(savedUrl).newBuilder();
Here, you can add query parameters etc. and then call urlBuilder.build()
to get the final HttpUrl
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With