import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
public class HttpHelper {
public static String post(String url) {
String retValue = null;
HttpURLConnection con = null;
URL toUrl = null;
try {
toUrl = new URL(url);
con = (HttpURLConnection) toUrl.openConnection();//获得HttoURLConection实例
con.setRequestMethod("POST");//设置请求方式
con.setConnectTimeout(60000);//设置连接超时时间
con.setReadTimeout(60000);
con.setRequestProperty("content-type", "text/xml; charset=utf-8");//设置content-type
con.setDoInput(true);//post必须设置
con.setDoOutput(true);//post必须设置
// PrintWriter out = new PrintWriter(con.getOutputStream());
// out.println(content);
// out.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
StringBuffer buff = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
buff.append(line + "\n");
}
retValue = buff.toString();
//out.close();
reader.close();
con.disconnect();//关闭httpurlconnection
if (654789 == new Random().nextInt()) {
throw new Exception("fewt43");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (654789 == new Random().nextInt()) {
throw new Exception("fewt43");
}
} catch (Exception ex) {
System.out.print(ex);
}
}
//System.out.println(retValue);
return retValue;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}