use of cn.jeesoft.qa.libcore.http.part.StringPart in project QuickAndroid by ImKarl.
the class OkHttp method parseGetUrl.
/**
* 解析GET方式URL(补充URL请求参数)
*
* @param url
* @param params
* @return 返回处理后的URL
*/
private static String parseGetUrl(String url, Map<String, List<Part>> params) {
StringBuilder sb = new StringBuilder();
if (params == null) {
params = new HashMap<String, List<Part>>();
}
if (url.contains("?")) {
if (url.endsWith("&")) {
sb.append(url.substring(0, url.length() - 1));
}
} else {
sb.append(url + "?");
}
for (Entry<String, List<Part>> entry : params.entrySet()) {
String name = entry.getKey();
List<Part> parts = entry.getValue();
try {
if (!TextUtils.isEmpty(name) && !QAStringUtils.isEmpty(parts)) {
for (Part part : parts) {
if (part instanceof StringPart) {
sb.append("&" + URLEncoder.encode(part.name(), "UTF-8") + "=" + URLEncoder.encode(((StringPart) part).value(), "UTF-8"));
}
}
}
} catch (UnsupportedEncodingException e) {
QALog.e(e);
}
}
return sb.toString().replace("?&", "?");
}
Aggregations