fork download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication3;
  7.  
  8.  
  9. import java.io.BufferedReader;
  10. import java.io.IOException;
  11. import java.io.InputStreamReader;
  12. import java.io.OutputStreamWriter;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16. import java.net.URLEncoder;
  17.  
  18. public class HttpPostForm {
  19. public static void main(String[] args) throws MalformedURLException, IOException
  20. {
  21. try {
  22. // Construct data
  23. String data = URLEncoder.encode("comment", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
  24.  
  25. // Send data
  26. URL url = new URL("https://2...content-available-to-author-only...h.hk/pr/res/668341.html");
  27. URLConnection conn = url.openConnection();
  28. conn.setDoOutput(true);
  29. OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  30. wr.write(data);
  31. wr.flush();
  32.  
  33. // Get the response
  34. BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  35. String line;
  36.  
  37. while ((line = rd.readLine()) != null) {
  38. System.out.println(line);
  39. }
  40.  
  41. wr.close();
  42. rd.close();
  43. } catch (Exception e) {
  44.  
  45. }
  46. }
  47. }
  48.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:18: error: class HttpPostForm is public, should be declared in a file named HttpPostForm.java
public class HttpPostForm {
       ^
1 error
stdout
Standard output is empty