Hãy thử HttpUrl
lớp (trong gói okhttp
).
//adds the pre-encoded query parameter to this URL's query string
addEncodedQueryParameter(String encodedName, String encodedValue)
//encodes the query parameter using UTF-8 and adds it to this URL's query string
addQueryParameter(String name, String value)
Lưu ý: nếu có đã được đặt tên/cặp giá trị với tên này, các chức năng này sẽ chỉ cần thêm một cặp
setEncodedQueryParameter(String encodedName, String encodedValue)
setQueryParameter(String name, String value)
Lưu ý: nếu có đã đặt tên/giá trị các cặp có tên này, các chức năng này sẽ xóa chúng và chỉ sau đó thêm cặp mới này
Ví dụ:
HttpUrl url = new HttpUrl.Builder()
.scheme("https")
.host("www.google.com")
.addPathSegment("search")
.addQueryParameter("q", "polar bears")
.build();
Nguồn
2015-08-21 18:17:11
thêm thông số vào http entitiy. – KOTIOS