Всем привет ! Никак не могу понять, почему у меня возникает ошибка peer not authenticated Вот код : Код | String idapp = "";//id приложения String settings = "audio";//запрашиваемые функции String redirect_uri = "http://api.vkontakte.ru/blank.html"; String login = "";//логин String pass = "";//пароль HttpClient httpclient = new DefaultHttpClient(); HttpPost post; HttpResponse response; //составляем url-строку List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("client_id", idapp)); qparams.add(new BasicNameValuePair("scope", settings)); qparams.add(new BasicNameValuePair("redirect_uri", redirect_uri)); qparams.add(new BasicNameValuePair("display", "wap")); qparams.add(new BasicNameValuePair("response_type", "token")); URI uri = URIUtils.createURI("http", "api.vkontakte.ru", -1, "/oauth/authorize", URLEncodedUtils.format(qparams, "UTF-8"), null); //запускал в снифере и смотрел редиректы. первый редирект содержит два параметра ip_h и to, которые затем записываются в невидимые поля формы авторизации //первый запрос. получаем значения to и ip_h т.д. post = new HttpPost(uri); response = httpclient.execute(post); post.abort(); String HeaderLocation = response.getFirstHeader("location").getValue(); URI RedirectUri = new URI(HeaderLocation); String ip_h= RedirectUri.getQuery().split("&")[1].split("=")[1]; String to_h=RedirectUri.getQuery().split("&")[3].split("=")[1]; //второй запрос. отправляем логин/пароль/to/ip_h post = new HttpPost("https://login.vk.com/?act=login&soft=1"); List <NameValuePair> postform = new ArrayList<NameValuePair>(); 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, HTTP.UTF_8)); response = httpclient.execute(post); post.abort(); //Если редирект есть - вход подтвержден. Переход на страницу разрешения доступа к функциям апи HeaderLocation = response.getFirstHeader("location").getValue(); post = new HttpPost(HeaderLocation); response = httpclient.execute(post); post.abort(); //подтверждать доступ нужно только при первой авторизации! при все последующий нас автоматически будет перебрасывать на страницу с access_token //извлекаем ссылку для подтверждения доступа к функциям.. String body = EntityUtils.toString(response.getEntity()); String form_action= "<form method=\"POST\" action=\""; int uri_start_index=body.indexOf(form_action)+form_action.length(); int uri_end_index=uri_start_index+body.substring(uri_start_index).indexOf('>')-1; String grant_access_uri="http://api.vkontakte.ru"+body.substring(uri_start_index,uri_end_index); //отправляем ссылку(для первой авторизации) или переходим по редиректу(если приложению уже был разрешен доступ) post = new HttpPost(grant_access_uri); response = httpclient.execute(post); post.abort(); //в последнем редиректер содержится необходимый нам access_token String access_token = response.getFirstHeader("location").getValue().split("#")[1].split("&")[0].split("=")[1]; System.out.println(access_token); response = httpclient.execute(post);
|
Полный стэк трейс : Код | Exception in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352) at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:131) at org.apache.http.conn.ssl.SSLSocketFactory.verifyHostname(SSLSocketFactory.java:648) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:623) at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:469) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:179) at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304) at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:444) at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:864) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:58) at test.VK.login(VK.java:103) at test.VK.test(VK.java:135) at test.VK.main(VK.java:145)
|
Подскажите пожалуйста.
|