0

i have posted a question for htmlunit in this link: how to use htmlunit with my android project

mainly i have a link, which i have get after login (i have login through web view) this link give me a simple page. in that page there is a textarea and a submit button. and there are some javascript too (i think these javascript run, when i press the submit button). i can do it through webview, but for some reason i don't want to use webview. whene i press submit button, it deliver the value of textarea and some value of hidden field with existing cookies(which are get when i logged in through webview) Post method. i need to do this without webview. now is there any other option beside htmlunit ?? i heard about HttpClient, HttpUrlConnection. but i don't know how to use them to solve my problem, because they are totaly new to me. i think if i use these class i have to run them in a seperate thread from UI tread. one more thing, after submitting it will redirect me to another page. i don't need to do anything with this redirected page.

thank you

Community
  • 1
  • 1
Shoshi
  • 2,254
  • 1
  • 29
  • 43
  • i have lost all my hope on HTMLUNIT. :( to gain my goal i have used HttpUrlConnection & Jsoup ... that works for me. [here is my procedure](http://stackoverflow.com/questions/14925061/how-to-get-all-cookies-or-cookies-url-from-android-webkit-cookiemanager/#14927665) i have post my code in answer. – Shoshi Feb 18 '13 at 05:55

1 Answers1

0

this is the same answer which i have given here

i have solve the problem. first of all i was getting the right cookie all time. so what was the problem then. either i was wrong to integrate the cookie with Jsoup or Jsoup was doing something wrong. so, first i have get the page with HttpUrlConnection and then parse it with Jsoup. like this:

URL form = new URL(uri.toString());
HttpUrlConnection connection1 = (HttpURLConnection)form.openConnection();
connection1.setRequestProperty("Cookie", my_cookie);
connection1.setReadTimeout(10000);
StringBuilder whole = new StringBuilder();
BufferedReader in = new BufferedReader(
new InputStreamReader(new BufferedInputStream(connection1.getInputStream())));
String inputLine;
while ((inputLine = in.readLine()) != null)
      whole.append(inputLine);
in.close();
Document doc = Jsoup.parse(whole.toString());

any advice about this code would be appreciated.

Community
  • 1
  • 1
Shoshi
  • 2,254
  • 1
  • 29
  • 43