#java #html #http #get
Пытаюсь получить HTML код со страницы своего приложения в Однокласстиках, в котором
есть session_key. Но большого куска кода в котором он присутствует почему то в ответе
нет. Не знаю в чем может быть проблема? При авторизации через браузер данный код присутствует.
public static HttpClient getThreadSafeClient(HttpClient client) {
client = new DefaultHttpClient();
ClientConnectionManager mgr = client.getConnectionManager();
HttpParams params = client.getParams();
client = new DefaultHttpClient(new ThreadSafeClientConnManager(params,
mgr.getSchemeRegistry()), params);
return client;
}
private static String getHtmlOK (){
HttpClient httpClient = new DefaultHttpClient();
org.apache.http.client.CookieStore cookieStore = new BasicCookieStore();
HttpContext context = new BasicHttpContext();
context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpPost httpPost = new HttpPost("https://www.ok.ru/https");
List nameValuePairList = new ArrayList(2);
nameValuePairList.add(new BasicNameValuePair("st.redirect", ""));
nameValuePairList.add(new BasicNameValuePair("st.asr", ""));
nameValuePairList.add(new BasicNameValuePair("st.posted", "set"));
nameValuePairList.add(new BasicNameValuePair("st.originalaction", "http://ok.ru/dk?cmd=AnonymLogin&st.cmd=anonymLogin"));
nameValuePairList.add(new BasicNameValuePair("st.fJS", "on"));
nameValuePairList.add(new BasicNameValuePair("st.st.screenSize", "1366 x 768"));
nameValuePairList.add(new BasicNameValuePair("st.st.browserSize", "628"));
nameValuePairList.add(new BasicNameValuePair("st.st.flashVer", "18.0.0"));
nameValuePairList.add(new BasicNameValuePair("st.email", "login"));
nameValuePairList.add(new BasicNameValuePair("st.password", "password"));
nameValuePairList.add(new BasicNameValuePair("st.iscode", "false"));
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line = null;
String newline = System.getProperty("line.separator");
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList));
HttpResponse response = httpClient.execute(httpPost, context);
Header locetionHeader = response.getFirstHeader("location");
httpClient = getThreadSafeClient(httpClient);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
// Выводим страницу на экран
String locetion;
if (locetionHeader != null){
locetion = locetionHeader.getValue();
HttpGet httpGet = new HttpGet(locetion);
response = httpClient.execute(httpGet, context);
httpGet = new HttpGet("http://ok.ru/game/1146333440");
httpClient = getThreadSafeClient(httpClient);
response = httpClient.execute(httpGet, context);
br = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
while (((line = br.readLine()) != null)) {
sb.append(line);
sb.append(newline);
}
}
} else {
System.out.println("А страничка-то и не загрузилась!!!");
System.out.println(locetionHeader.getValue());
}
}
catch (IOException e){
System.out.println("Проблемы со связью");
}
System.out.println(sb);
return sb.toString();
}
Ответы
Ответ 1
Очень часто вывод тормозят escape-символы, кавычки итд. У меня было подобное. тормозил BOM. Сравните коды, из браузера и в буфере, может в символ уперся.
Комментариев нет:
Отправить комментарий