mwangibrian21

Untitled

Jul 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. String final_url = "http://localhost/makeup/index.php";
  2.    
  3.     public Grade() {
  4.         // Empty constructor
  5.         System.out.println("INITIALIZED");
  6.     }
  7.    
  8.     public String getGrade( int stumark, int stunumber ) {
  9.         String result = "";
  10.        
  11.         try {
  12.             URL url = new URL(final_url);
  13.             HttpURLConnection con = (HttpURLConnection) url.openConnection();
  14.             con.setRequestMethod("POST");
  15.             String urlparams = "stumark=" + Integer.toString(stumark) + "&stunumber=" + Integer.toString(stunumber);
  16.             con.setDoOutput(true);
  17.            
  18.            
  19.             DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  20.             wr.writeBytes(urlparams);
  21.             wr.flush();
  22.             wr.close();
  23.            
  24.             int responceCode = con.getResponseCode();
  25.             System.out.println("Sending POST request to : " + final_url );
  26.             BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()) );
  27.             String inputLine;
  28.             StringBuffer response = new StringBuffer();
  29.             while( (inputLine = in.readLine() ) != null ) {
  30.                 response.append( inputLine );
  31.             }
  32.             in.close();
  33.            
  34.             System.out.println("Result : " + response );
  35.             result = response.toString();
  36.         }catch( Exception e ) {
  37.             System.out.println(e.getMessage());
  38.         }
  39.        
  40.         return result;
  41.     }
Add Comment
Please, Sign In to add comment