private Document searchkeyword(String searchkeyword, String host){
String apiUrl = "http://xxxxxxx?name=%s&key=%s&page=1";
Document document = null;
try{
String unicode = encoding(searchkeyword);
String name = URLEncoder.encode(searchkeyword, "UTF-8");
String url = String.format(apiUrl, name, unicode);
// 将 转换为 %25 事先转换 这样请求的时候 URL不会再decode
String newUrl = StringUtils.replace(url, "\", "%25");
document = jsoupConnectGet(host, newUrl, null);
}catch (Throwable t){
log.error("searchkeyword()失败-->>", t);
}
return document;
}
public static String encoding(String str) {
if(StringUtils.isBlank(str)){
return "";
}
char[] utfBytes = str.toCharArray();
String unicodeBytes = "";
for (int i = 0; i < utfBytes.length; i++) {
String hexB = Integer.toHexString(utfBytes[i]);
if (hexB.length() <= 2) {
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "\u" + hexB;
}
return unicodeBytes;
}