Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > : how to supply login/password to a web site

Reply
Thread Tools

: how to supply login/password to a web site

 
 
zigzagdna
Guest
Posts: n/a
 
      02-17-2012

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.

Thanks,
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      02-17-2012
On Thu, 16 Feb 2012 17:53:24 -0800 (PST), zigzagdna
<> wrote, quoted or indirectly quoted someone who
said :

>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

This is much easier than you would imagine.

see http://mindprod.com/jgloss/authentication.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
One of the most useful comments you can put in a program is
"If you change this, remember to change ?XXX? too".

 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      02-17-2012
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.

And if it is a ASP.NET web side using view stat, then you
will have some extra challenges.

Arne

 
Reply With Quote
 
zigzagdna
Guest
Posts: n/a
 
      02-17-2012
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.
>
> And if it is a ASP.NET web side using view stat, then you
> will have some extra challenges.
>
> Arne

Thanks so much, internet newsgroups are so helpful.
 
Reply With Quote
 
zigzagdna
Guest
Posts: n/a
 
      02-17-2012
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.
>
> And if it is a ASP.NET web side using view stat, then you
> will have some extra challenges.
>
> Arne


Thanks a lot for your expert advise, internet newsgroups are so
helpful.
 
Reply With Quote
 
zigzagdna
Guest
Posts: n/a
 
      02-17-2012
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.

>
> > And if it is a ASP.NET web side using view stat, then you
> > will have some extra challenges.

>
> > Arne

>
> Thanks a lot for your expert advise, internet newsgroups are so
> helpful.- Hide quoted text -
>
> - Show quoted text -


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 . My yahoo mail is decatvated.

Thanks a lot

 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      02-17-2012
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_);
}
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
 
Reply With Quote
 
zigzagdna
Guest
Posts: n/a
 
      02-18-2012
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_);
> * * * * *}
> * * * * *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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber XML 1 12-25-2007 11:48 PM
Free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-24-2007 04:26 PM
List of free web site design, web site backgrounds, web site layoutsresources cyber HTML 0 12-21-2007 03:47 PM
List of free web site design, web site backgrounds, web site layoutsweb sites cyber HTML 1 12-19-2007 09:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57