|
Socket is closed вконтакте
#38422199
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
|
Здравствуйте, никак не могу понять в чем проблема
Exception in thread "main" java.net.SocketException: Socket is closed
Коды :
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62.
public class InsecureHttpClientFactory {
DefaultHttpClient hc;
public DefaultHttpClient buildHttpClient() throws NoSuchAlgorithmException,
KeyManagementException,
KeyStoreException,
UnrecoverableKeyException {
hc = new DefaultHttpClient();
//configureProxy();
configureCookieStore();
configureSSLHandling();
return hc;
}
private void configureProxy() {
HttpHost proxy = new HttpHost("proxy.example.org", 3182);
hc.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
private void configureCookieStore() {
CookieStore cStore = new BasicCookieStore();
hc.setCookieStore(cStore);
}
private void configureSSLHandling() throws NoSuchAlgorithmException,
KeyManagementException,
KeyStoreException,
UnrecoverableKeyException {
Scheme http =
new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
SSLSocketFactory sf = buildSSLSocketFactory();
Scheme https = new Scheme("https", 443, sf);
SchemeRegistry sr = hc.getConnectionManager().getSchemeRegistry();
sr.register(http);
sr.register(https);
}
private SSLSocketFactory buildSSLSocketFactory() throws NoSuchAlgorithmException,
KeyManagementException,
KeyStoreException,
UnrecoverableKeyException {
TrustStrategy ts = new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates,
String s) throws CertificateException {
return true; // heck yea!
}
};
SSLSocketFactory sf = null;
try {
/* build socket factory with hostname verification turned off. */
sf =
new SSLSocketFactory(ts, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return sf;
}
}
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19.
postform.add(new BasicNameValuePair("q", "1"));
postform.add(new BasicNameValuePair("ip_h", ip_h));
postform.add(new BasicNameValuePair("from_host", "api.vkontakte.ru"));
postform.add(new BasicNameValuePair("to", to_h));
postform.add(new BasicNameValuePair("expire", "0"));
postform.add(new BasicNameValuePair("email", login));
postform.add(new BasicNameValuePair("pass", pass));
post.setEntity(new UrlEncodedFormEntity(postform, "UTF-8"));
response = httpclient.execute(post);
post.abort();
//Если редирект есть - вход подтвержден. Переход на страницу разрешения доступа к функциям апи
HeaderLocation = response.getFirstHeader("location").getValue();
post = new HttpPost(HeaderLocation);
response = httpclient.execute(post);
post.abort();
System.out.println("HeaderLocation" + HeaderLocation);
//подтверждать доступ нужно только при первой авторизации! при все последующий нас автоматически будет перебрасывать на страницу с access_token
//извлекаем ссылку для подтверждения доступа к функциям..
String body = EntityUtils.toString(response.getEntity());
На последней строчке обрывается.
Может кто подсказать ?
|
|
|