Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question