/**
* 提交请求 chenjy 2011-9-8
*
* @param urlStr
* @param map
* @return
* @throws Exception String
*/
public static String post(String urlStr, Map<String, String> map) {
if (urlStr == null || map == null || map.size() == 0) {
return null;
}
try {
StringBuffer urt = new StringBuffer();
urt.append(urlStr);
urt.append("?");
boolean add = true;
for (Entry e : map.entrySet()) {
if (add) {
add = false;
} else {
urt.append("&");
}
urt.append(e.getKey());
urt.append("=");
urt.append(e.getValue() == null ? "" : e.getValue());
}
System.out.println(urt.toString());
String responseContent = null;
HttpURLConnection url_con = null;
URL url = new URL(urt.toString());
url_con = (HttpURLConnection) url.openConnection();
url_con.setRequestMethod("POST");
url_con.setReadTimeout(60000);
url_con.setDoOutput(true);
StringBuffer params = new StringBuffer();
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
InputStream in = url_con.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String tempLine = rd.readLine();
StringBuffer tempStr = new StringBuffer();
while (tempLine != null) {
tempStr.append(tempLine);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
in.close();
System.out.println(tempStr.toString());
return tempStr.toString();
} catch (Exception e1) {
return null;
}
}
* 提交请求 chenjy 2011-9-8
*
* @param urlStr
* @param map
* @return
* @throws Exception String
*/
public static String post(String urlStr, Map<String, String> map) {
if (urlStr == null || map == null || map.size() == 0) {
return null;
}
try {
StringBuffer urt = new StringBuffer();
urt.append(urlStr);
urt.append("?");
boolean add = true;
for (Entry e : map.entrySet()) {
if (add) {
add = false;
} else {
urt.append("&");
}
urt.append(e.getKey());
urt.append("=");
urt.append(e.getValue() == null ? "" : e.getValue());
}
System.out.println(urt.toString());
String responseContent = null;
HttpURLConnection url_con = null;
URL url = new URL(urt.toString());
url_con = (HttpURLConnection) url.openConnection();
url_con.setRequestMethod("POST");
url_con.setReadTimeout(60000);
url_con.setDoOutput(true);
StringBuffer params = new StringBuffer();
byte[] b = params.toString().getBytes();
url_con.getOutputStream().write(b, 0, b.length);
url_con.getOutputStream().flush();
url_con.getOutputStream().close();
InputStream in = url_con.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String tempLine = rd.readLine();
StringBuffer tempStr = new StringBuffer();
while (tempLine != null) {
tempStr.append(tempLine);
tempLine = rd.readLine();
}
responseContent = tempStr.toString();
rd.close();
in.close();
System.out.println(tempStr.toString());
return tempStr.toString();
} catch (Exception e1) {
return null;
}
}