Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 1.67 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android: Eclipse/Netbeans Conflict HTML
  2. public class LogTest {
  3.  
  4.   public String doSubmit(String url, Map<String, String> data) throws Exception {
  5.     URL siteUrl = new URL(url);
  6.     HttpURLConnection conn = (HttpURLConnection) siteUrl.openConnection();
  7.     conn.setRequestMethod("POST");
  8.     conn.setDoOutput(true);
  9.     conn.setDoInput(true);
  10.  
  11.     DataOutputStream out = new DataOutputStream(conn.getOutputStream());
  12.  
  13.     Set keys = data.keySet();
  14.     Iterator keyIter = keys.iterator();
  15.     String content = "";
  16.     for (int i = 0; keyIter.hasNext(); i++) {
  17.         Object key = keyIter.next();
  18.         if (i != 0) {
  19.             content += "&";
  20.         }
  21.         content += key + "=" + URLEncoder.encode(data.get(key), "UTF-8");
  22.     }
  23.     out.writeBytes(content);
  24.     out.flush();
  25.     out.close();
  26.     BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  27.     String line = "";
  28.     String html = "";
  29.     while ((line = in.readLine()) != null) {
  30.         html += line + "n";
  31.     }
  32.     in.close();
  33.     return html;
  34.  
  35. }
  36.  
  37. public static void main(String[] args) {
  38.     String html = "no html";
  39.     try {
  40.         LogTest test = new LogTest();
  41.         String url = "http://www.cupertino.schoolloop.com/portal/login?login_name=siddhantdanger&password=11616sid"
  42.                 + "&event_override=login";
  43.         Map<String, String> data = new HashMap<String, String>();
  44.         data.put("login_name", "aLogin");
  45.         data.put("password", "aPass");
  46.         data.put("event_override", "login");
  47.         data.put("etarget", "login_form");
  48.         html = test.doSubmit(url, data);
  49.     } catch (Exception e) {
  50.         e.printStackTrace();
  51.     }
  52.     System.out.println(html);
  53.  
  54.  
  55.     }
  56. }