I am using OkHttp 2.4.0.
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("www.something.com")
.addPathSegment("/api/v1/doc")
.build();
The expected url is: https://www.something.com/api/v1/doc
What I get is: https://www.something.com%2Fapi%2Fv1%2Fdoc
The "/" in the pathSegment are replaced with "%2F". Why does this occur and how can it be avoided since i get an invalid Url exception because apache does not allow "%2F" in a url.
Try this:
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("www.something.com")
.addPathSegment("api")
.addPathSegment("v1")
.addPathSegment("doc")
.build();
This solution is a little bit more elegant, and OkHttp doesn't replace slashes in this case :)
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("www.something.com")
.addPathSegments("api/v1/doc")
.build();
Delete the slashes and concatenate the segments like this:
HttpUrl url=new HttpUrl.Builder()
.scheme("https")
.host("www.something.com")
.addPathSegment("api")
.addPathSegment("v1")
.addPathSegment("doc")
.build();
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