1 package org.kuali.ole.utility;
2
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
8 import java.io.OutputStreamWriter;
9 import java.io.Writer;
10 import java.net.URL;
11 import java.net.URLConnection;
12
13
14
15
16
17
18
19
20 public class HttpUtil {
21
22 private static final Logger LOG = LoggerFactory.getLogger(HttpUtil.class);
23
24 public static String postData(String target, String content)
25 throws Exception {
26
27 String response = "";
28 URL url = new URL(target);
29 URLConnection conn = url.openConnection();
30 conn.setDoInput(true);
31 conn.setDoOutput(true);
32 conn.setUseCaches(false);
33 conn.setRequestProperty("Content-Type",
34 "application/x-www-form-urlencoded");
35
36 Writer w = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
37 w.write(content);
38 w.close();
39 BufferedReader in = new BufferedReader(new InputStreamReader(
40 conn.getInputStream()));
41 String temp;
42 while ((temp = in.readLine()) != null) {
43 response += temp + "\n";
44 }
45 temp = null;
46 in.close();
47 LOG.debug("Server response: " + response);
48 return response;
49
50 }
51
52 }