001 package org.kuali.ole.utility; 002 003 import java.io.BufferedReader; 004 import java.io.InputStreamReader; 005 import java.io.OutputStreamWriter; 006 import java.io.Writer; 007 import java.net.URL; 008 import java.net.URLConnection; 009 010 /** 011 * Created by IntelliJ IDEA. 012 * User: ND6967 013 * Date: 12/21/11 014 * Time: 5:17 PM 015 * To change this template use File | Settings | File Templates. 016 */ 017 public class HttpUtil { 018 019 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HttpUtil.class); 020 public static String postData(String target, String content) 021 throws Exception { 022 023 String response = ""; 024 URL url = new URL(target); 025 URLConnection conn = url.openConnection(); 026 conn.setDoInput(true); 027 conn.setDoOutput(true); 028 conn.setUseCaches(false); 029 conn.setRequestProperty("Content-Type", 030 "application/x-www-form-urlencoded"); 031 032 Writer w = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); 033 w.write(content); 034 w.close(); 035 BufferedReader in = new BufferedReader(new InputStreamReader( 036 conn.getInputStream())); 037 String temp; 038 while ((temp = in.readLine()) != null) { 039 response += temp + "\n"; 040 } 041 temp = null; 042 in.close(); 043 LOG.debug("Server response: " + response); 044 return response; 045 046 } 047 048 }