Advertisement
Noneatme

Untitled

Jan 16th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. // Query //
  2.     public static String SendQuery(String urls, String query) throws IOException
  3.     {
  4.         CFrame.setStatus("Befehl wird gesendet...");
  5.         URL url = new URL("http://noneatme.de/Kadcon_Flohmarkt/" + urls + ".php");
  6.         conn = (HttpURLConnection) url.openConnection();
  7.        
  8.         // Session //
  9.        
  10.         String agent="Applet";
  11.         String type="application/x-www-form-urlencoded";
  12.        
  13.         conn.setDoInput(true);
  14.         conn.setDoOutput(true);
  15.         conn.setRequestMethod("POST");
  16.         conn.setRequestProperty( "User-Agent", agent );
  17.         conn.setRequestProperty( "Content-Type", type );
  18.         conn.setRequestProperty( "Content-Length", ""+query.length());
  19.        
  20.         if(session_id.length() > 1)
  21.         {
  22.             System.out.println(session_id);
  23.             conn.setRequestProperty("Cookie", "PHPSESSID=" + session_id);
  24.             conn.connect();
  25.         }
  26.        
  27.  
  28.         java.io.OutputStream out = conn.getOutputStream();
  29.         out.write(query.getBytes());
  30.        
  31.         BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  32.            
  33.         String inputLine;
  34.         String resultSet = "";
  35.        
  36.         while((inputLine=in.readLine())!=null)
  37.         {
  38.             resultSet = resultSet+inputLine+"\n";
  39.             System.out.print(inputLine+"\n");
  40.         }
  41.        
  42.         if(urls.equals("login"))
  43.         {
  44.             String headerName=null;
  45.             for (int i=1; (headerName = conn.getHeaderFieldKey(i))!=null; i++)
  46.             {
  47.                 if (headerName.equals("Set-Cookie"))
  48.                 {                  
  49.                     String cookie = conn.getHeaderField(i);  
  50.                     cookie = cookie.substring(0, cookie.indexOf(";"));
  51.                     String cookieName = cookie.substring(0, cookie.indexOf("="));
  52.                     String cookieValue = cookie.substring(cookie.indexOf("=") + 1, cookie.length());
  53.                    
  54.                     if(cookieName.equals("PHPSESSID"))
  55.                     {
  56.                         session_id = cookieValue;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         in.close();
  62.         int rc = conn.getResponseCode();
  63.         System.out.print("Response Code = "+rc+"\n");
  64.         String rm=conn.getResponseMessage();
  65.         System.out.print("Response Message = "+rm+"\n");
  66.        
  67.         out.close();
  68.         CFrame.setStatus("Befehl gesendet.");
  69.         return resultSet;
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement