I
I
ideas4ru2012-10-19 10:59:08
Java
ideas4ru, 2012-10-19 10:59:08

Why doesn't the Java application connect to the Vkontakte API?

Hello everyone,
There was a problem with the VKontakte API, working through Java, not Android.
The code works fine for google.com, yahoo.com, but when accessing the generated link it crashes with the exception java.net.SocketTimeoutException: connect timed out.
Although if you take the generated link and copy it into the address bar of the browser, you get a response in JSON format.
{"response":[{"uid":my_id,"first_name":"my_name","last_name":"my_last_name"}]}

String request = "https://api.vk.com/method/users.get?uids=" + userId + "&fields=first_name,last_name&access_token=" + accessToken;

        try {
          System.setProperty("http.proxyHost", PROXY_IP);
          System.setProperty("http.proxyPort", "8080");

          URL url = new URL(request);
          URLConnection con = url.openConnection();
          
                    //EXCEPTION HERE!!
          BufferedReader inReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

          String inputLine;
              while ((inputLine = inReader.readLine()) != null)
                  System.out.println(inputLine);
              inReader.close();

        } catch (Exception e) {
          e.printStackTrace(System.err);
        }

I run the program on a local computer in the company's network, using a proxy. Perhaps the problem is in it, but for google.com I see the HTML code in the output.
What will be the thoughts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ivnik, 2012-10-19
@ivnik

Are you querying Google also via https? Have a look at docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

2.2) HTTPS
The https (http over SSL) protocol handler has its own set of properties:
htttps.proxyHost
https.proxyPort

A
Artur Smirnov, 2012-10-19
@wisd

Google is probably open directly, without a proxy.
You would show us an exception. But most likely you need to specify more authentication in the proxy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question