使用java开发微信公众号系列-公共类( 三 )


String crlf = System.getProperty("line.separator");
while (tempLine != null) {
tempStr.append(tempLine);
tempStr.append(crlf);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
} catch (IOException e) {
 
} finally {
if (url_con != null) {
url_con.disconnect();
}
}
return responseContent;
}
/**
* 将参数转换成string
*
* @param paramMap 参数映射表
* @param requestEncoding 编码
* @return
* @throws UnsupportedEncodingException
*/
private static String getMapParamsToStr(Map<String, String> paramMap, String requestEncoding) throws IOException {
StringBuffer params = new StringBuffer();
// 设置边界
Set<String> set = paramMap.keySet();
for (String key : set) {
params.append(key);
params.append("=");
params.append(URLEncoder.encode(paramMap.get(key), requestEncoding));
params.append("&");
}
if (params.length() > 0) {
params = params.deleteCharAt(params.length() - 1);
}
return params.toString();
}
}




推荐阅读