/**
*根据url地址和要发送的字符串通过http协议用post方法把xml字符串用流格式发送到指定url的网页。
* @param sUrl 要发送的url地址
* @param sXML 要发送的XML
* @param sContent 要发送的字符串
* @throws
* @return 通过该次发送到目标网页并返回的结果字符串。
*/
public String doHttpPost(String strUrl, String sXML) throws
IOException {
StringBuffer strReturnVal = new StringBuffer("");
HttpURLConnection httpURLConnection = null;
OutputStreamWriter osw = null;
try {
//开始发送的时间
java.net.URL url = new java.net.URL(strUrl);
java.net.URLConnection urlcn = url.openConnection();
httpURLConnection = (HttpURLConnection) urlcn;
httpURLConnection.setRequestMethod("POST");
System.setProperty("sun.net.client.defaultConnectTimeout", "6000");
System.setProperty("sun.net.client.defaultReadTimeout", "6000");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
osw = new OutputStreamWriter(httpURLConnection.
getOutputStream(),
"GB2312");
osw.write(sXML);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (osw != null) {
osw.close();
}
}
InputStreamReader isr = null;
try {
isr = new InputStreamReader(httpURLConnection.
getInputStream(),
"GB2312");
while (true) {
char[] c = new char[1024];
int ilen = isr.read(c);
if (ilen <= 0) {
break;
}
strReturnVal = strReturnVal.append(new String(c, 0, ilen));
}
return strReturnVal.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (isr != null) {
isr.close();
}
}
}