loadStrings URL 403 error

I did some searching and the previous solutions don't apply to my situation.

I am trying to loadStrings("http://www.interpol.int");

I believe it's because of the ".int" domain extension, but I could be wrong.

This is throwing an error: java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.interpol.int

It works with "interpol.com" but that site is no use because it embeds the frame from interpol.int and Processing can't access the frame.

    [0] "<HTML>"
    [1] "<HEAD>"
    [2] "<TITLE>www.interpol.com</TITLE>"
    [3] "<META NAME="robots" CONTENT="noindex">"
    [4] "</HEAD>"
    [5] "<FRAMESET FRAMESPACING="0" BORDER="0" FRAMEBORDER=No ROWS="100%,*">"
    [6] "  <FRAME SRC="http://www.interpol.int">"
    [7] "</FRAMESET>"
    [8] "<NOFRAMES>"
    [9] "Sorry, your browser doesn't seem to support frames! <br>"
    [10] "Proceed to <A href="http://www.interpol.int">http://www.interpol.int</A>; manually."
    [11] "</NOFRAMES>"
    [12] "</HTML>"

I found some java code:

import java.net.*;
import java.io.*;

URL url;

void setup() {
    try {
        url = new URL("http://www.interpol.int");
    } catch (MalformedURLException ex) {
        throw new RuntimeException(ex);
    }
    loadStrings(url);
    println(url);
}

class MyClass {
    private URL url = new URL("http://www.interpol.int");

    public MyClass() throws MalformedURLException {}
}

(Not sure why the code view is adding HTML wrappers to the URL's)

I am having trouble getting this to work with loadStrings();

"The method loadString(File) in the type PApplet is not applicable for the arguments(URL)"

What can I do?

Thx

Tagged:

Answers

  • edited June 2014

    this could be intentionally because they want everybody to use the frames

    403 means forbidden

    this works for other site but not for interpol

    void setup() {
      String[] a1=loadStrings("http"+"://www.heise.de");
      println(join(a1, ' '));
    }
    
  • edited June 2014

    Here is the solution:

    // import libraries
    import java.net.*;
    import java.io.*;
    
    URL url;
    
    void setup() {
      try {
        // Create a URL object
        URL url = new URL("INTERPOL-URL-HERE");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;     rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");
        // Read all of the text returned by the HTTP server
        BufferedReader in = new BufferedReader
          (new InputStreamReader(conn.getInputStream(), "UTF-8"));
    
        String htmlText;
    
        while ( (htmlText = in.readLine ()) != null) {
          // Keep in mind that readLine() strips the newline characters
          System.out.println(htmlText);
        }
        in.close();
      } 
      catch (MalformedURLException e) {
        e.printStackTrace();
      } 
      catch (IOException e) {
        e.printStackTrace();
      }
    }
    
Sign In or Register to comment.