Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12162
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.glorb.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!9g2000yqo.googlegroups.com!not-for-mail |
|---|---|
| From | zigzagdna <zigzagdna@yahoo.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: : how to supply login/password to a web site |
| Date | Sat, 18 Feb 2012 08:30:39 -0800 (PST) |
| Organization | http://groups.google.com |
| Lines | 90 |
| Message-ID | <3a637961-94c2-43de-a2dd-eceb5ca93a10@9g2000yqo.googlegroups.com> (permalink) |
| References | <6ba6c81f-c538-4ce3-80fc-d943769a6fb0@t2g2000yqk.googlegroups.com> <4f3db890$0$291$14726298@news.sunsite.dk> <88fa6fed-0821-46d4-b693-9fd8243e91b3@eb6g2000vbb.googlegroups.com> <684df406-0054-4730-a290-178b901860aa@he5g2000vbb.googlegroups.com> <4f3ecd7d$0$281$14726298@news.sunsite.dk> |
| NNTP-Posting-Host | 148.177.1.210 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | posting.google.com 1329582639 4442 127.0.0.1 (18 Feb 2012 16:30:39 GMT) |
| X-Complaints-To | groups-abuse@google.com |
| NNTP-Posting-Date | Sat, 18 Feb 2012 16:30:39 +0000 (UTC) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | 9g2000yqo.googlegroups.com; posting-host=148.177.1.210; posting-account=PUA9dQoAAAAWB6fqjaJDJmTx7eb4x-f4 |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-Header-Order | ARLEUHCNK |
| X-HTTP-UserAgent | Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.2; MS-RTC LM 8; .NET CLR 1.1.4322),gzip(gfe) |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:12162 |
Show key headers only | View raw
On Feb 17, 4:58 pm, Arne Vajhøj <a...@vajhoej.dk> wrote:
> On 2/17/2012 7:35 AM, zigzagdna wrote:
>
>
>
>
>
> > On Feb 16, 9:47 pm, zigzagdna<zigzag...@yahoo.com> wrote:
> >> On Feb 16, 9:16 pm, Arne Vajhøj<a...@vajhoej.dk> wrote:
> >>> On 2/16/2012 8:53 PM, zigzagdna wrote:
> >>>> I have a web site which I want to access from a java program.
> >>>> Problem is web site requires a login and password. However web site
> >>>> Does not provide in URL a way to specify login and password.
> >>>> Is there any way in my java progam I can supply various key strokes
> >>>> which I will
> >>>> Type when I logon manually.
>
> >>> Typical the web site will use form based login.
>
> >>> In which case you will need to first send a POST to the
> >>> action URL of the login page and then request the stuff you
> >>> need using the session cookie you got back from the login.
>
> >>> I will strongly recommend Apache HttpClient over raw
> >>> (Http)URLConnection.
>
> >>> I do have some examples on the shelf if you are interested.
> > Can you post your examples in this thread, else please send them to
> > me at
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.http.NameValuePair;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.entity.UrlEncodedFormEntity;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.client.methods.HttpPost;
> import org.apache.http.impl.client.DefaultHttpClient;
> import org.apache.http.message.BasicNameValuePair;
> import org.apache.http.protocol.HTTP;
> import org.apache.http.util.EntityUtils;
>
> public class Login {
> private HttpClient client;
> public Login() {
> client = new DefaultHttpClient();
> }
> public void login(String url, String userField, String userValue,
> String passField, String passValue) throws Exception {
> List<NameValuePair> nvp = new ArrayList<NameValuePair>();
> nvp.add(new BasicNameValuePair(userField, userValue));
> nvp.add(new BasicNameValuePair(passField, passValue));
> post(url, nvp);
> }
> public String get(String url) throws Exception {
> HttpGet met = new HttpGet(url);
> return EntityUtils.toString(client.execute(met).getEntity());
> }
> public String post(String url, List<NameValuePair> nvp) throws
> Exception {
> HttpPost met = new HttpPost(url);
> if (nvp != null) {
> met.setEntity(new UrlEncodedFormEntity(nvp, HTTP.UTF_8));
> }
> return EntityUtils.toString(client.execute(met).getEntity());
> }
> public static void main(String[] args) throws Exception {
> Login lgi = new Login();
> lgi.get("http://localhost:8080/login/open/test.jsp");
> lgi.login("http://localhost:8080/login/j_security_check",
> "j_username", "userarne", "j_password", "xxxxxx");
>
> System.out.println(lgi.get("http://localhost:8080/login/open/test.jsp"));
> }
>
> }
>
> Arne- Hide quoted text -
>
> - Show quoted text -
Arne:
Thanks a lot.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
: how to supply login/password to a web site zigzagdna <zigzagdna@yahoo.com> - 2012-02-16 17:53 -0800
Re: : how to supply login/password to a web site Roedy Green <see_website@mindprod.com.invalid> - 2012-02-16 17:59 -0800
Re: : how to supply login/password to a web site Arne Vajhøj <arne@vajhoej.dk> - 2012-02-16 21:16 -0500
Re: : how to supply login/password to a web site zigzagdna <zigzagdna@yahoo.com> - 2012-02-16 18:46 -0800
Re: : how to supply login/password to a web site zigzagdna <zigzagdna@yahoo.com> - 2012-02-16 18:47 -0800
Re: : how to supply login/password to a web site zigzagdna <zigzagdna@yahoo.com> - 2012-02-17 04:35 -0800
Re: : how to supply login/password to a web site Arne Vajhøj <arne@vajhoej.dk> - 2012-02-17 16:58 -0500
Re: : how to supply login/password to a web site zigzagdna <zigzagdna@yahoo.com> - 2012-02-18 08:30 -0800
csiph-web