如何发布一些饼干形式 [英] how to post a form with some cookie

查看:191
本文介绍了如何发布一些饼干形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发布了在这个环节的HtmlUnit一个问题:如何可以使用HtmlUnit,与我的Andr​​oid项目

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

主要是我有一个链接,这是我登录后得到(我已经通过Web视图登录)此链接给我一个简单的页面。在页面上,有一个textarea和一个提交按钮。并有一些JavaScript太(我觉得这些JavaScript的运行,当我preSS提交按钮)。我能做到这一点通过web视图,但由于某些原因,我不希望使用web视图。 whene我preSS提交按钮,它提供textarea的价值,并与现有的Cookie(这是获得当我通过的WebView登录)Post方法隐藏字段的一些价值。我需要做的这一点没有web视图。现在有没有旁边的HtmlUnit任何其他选项?我听说HttpClient的,HttpURLConnection类。但我不知道如何使用它们来解决我的问题,因为他们是完全以新的我。我想如果我使用这些类我必须从UI胎面一个单独的线程运行。还有一件事,提交后我会重定向到另一页。我不需要这种重定向页面做任何事情。

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.

感谢您

推荐答案

这是我已经给出了相同的答案<一个href=\"http://stackoverflow.com/questions/14925061/how-to-get-all-cookies-or-cookies-url-from-android-webkit-cookiemanager/#14927665\">here

this is the same answer which i have given here

我有解决的问题。首先,我居然也得到了正确的饼干所有的时间。那么究竟是什么原因呢。无论是我错了与Jsoup或Jsoup是做错了cookie的集成。所以,首先我得与HttpURLConnection类的页面,然后用Jsoup解析它。像这样的:

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());

这个code任何意见将AP preciated。

any advice about this code would be appreciated.

这篇关于如何发布一些饼干形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆