Trying to read bukkit forums. ERROR: 403

Discussion in 'Plugin Development' started by Deckerz, Jul 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Deckerz

    While trying to read the forums for certain html code i get error 403. I know that means forbidden is it the way i am doing it or is it that i cant access this site using java?

    Code:java
    1.  
    2. URL url = new URL("[url]https://forums.bukkit.org/[/url]");
    3. HttpURLConnection conect = (HttpURLConnection) url.openConnection();
    4. InputStream is = conect.getInputStream();
    5. String line;
    6. while(!(line = reader.readLine()).equalsIgnoreCase("</html>")){
    7. if(line.endsWith("</a></h3>")){
    8. System.out.println(line);
    9. }
    10. }
    11.  


    i also tried this

    Code:java
    1. package com.declanmc.test;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.InputStreamReader;
    5. import java.net.MalformedURLException;
    6. import java.net.URL;
    7. import java.sql.Connection;
    8.  
    9. public class test {
    10.  
    11.  
    12. public static void main(String[] args) {
    13. try {
    14. initTest();
    15. } catch (Exception e) {
    16. e.printStackTrace();
    17. }
    18.  
    19. }
    20.  
    21. private static void initTest() throws Exception{
    22.  
    23. URL url = new URL("[url]http://forums.bukkit.org/[/url]");
    24. BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    25. String line;
    26. while(!(line = reader.readLine()).equalsIgnoreCase("</html>")){
    27. if(line.endsWith("</a></h3>")){
    28. System.out.println(line);
    29. }
    30. }
    31.  
    32. }
    33.  
    34. }
    35.  


    ignore the '[/url]' that something the forums does automatically :p
     
  2. Offline

    AmShaegar

    You have to fake your user agent. Bukkit uses cloudflare which block user agent "java".
     
  3. Offline

    Deckerz

    how would i do that?
     
  4. Offline

    AmShaegar

    establish a proper http connection like so:
    Code:java
    1. URLConnection connection = new URL(url).openConnection();
    2. connection.setRequestProperty("User-Agent", userAgent);
    3. connection.setRequestProperty("Referrer", referrer);
    4. BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    5. while (reader.ready()) {
    6. response = response.append(reader.readLine()+System.getProperty("line.separator"));
    7. }
    8. reader.close();
     
Thread Status:
Not open for further replies.

Share This Page