Angus
asked on
Signing in using Java
Folks,
I am writing a program for people to manage their ebay auctions. However I have come to a hurdle.
If you look at this link:
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193
If you scroll down you see in the summary of the auction "History: Purchases" which is a link to:
http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193
However to view this page it is required to sign in. At the moment I am downloading details of the auctions using this code, however it does not work to view the links which require sign in.
How can I by pass this? The success of this software package greatly depends on the ability to full manage the auctions for the owner - i.e all the purchases etc.. etc.. Any suggestions??
I have created test ebay id:
id: expertsexchangetest
password: experts123
String readString = "";
String searchPageURL = "http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193";
BufferedReader HTMLpage;
URL url;
URLConnection urlConnection;
boolean stop = false;
try
{
//Connecting to URL
url = new URL(searchPageURL);
urlConnection = url.openConnection();
HTMLpage = new BufferedReader(new InputStreamReader(url.open Stream())) ;
//Looping through Web Page
while((readString = HTMLpage.readLine()) != null && !stop)
{
System.out.println(readStr ing);
}
HTMLpage.close();
}
I am writing a program for people to manage their ebay auctions. However I have come to a hurdle.
If you look at this link:
http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193
If you scroll down you see in the summary of the auction "History: Purchases" which is a link to:
http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193
However to view this page it is required to sign in. At the moment I am downloading details of the auctions using this code, however it does not work to view the links which require sign in.
How can I by pass this? The success of this software package greatly depends on the ability to full manage the auctions for the owner - i.e all the purchases etc.. etc.. Any suggestions??
I have created test ebay id:
id: expertsexchangetest
password: experts123
String readString = "";
String searchPageURL = "http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193";
BufferedReader HTMLpage;
URL url;
URLConnection urlConnection;
boolean stop = false;
try
{
//Connecting to URL
url = new URL(searchPageURL);
urlConnection = url.openConnection();
HTMLpage = new BufferedReader(new InputStreamReader(url.open
//Looping through Web Page
while((readString = HTMLpage.readLine()) != null && !stop)
{
System.out.println(readStr
}
HTMLpage.close();
}
Can you please be clear what you wanted is to pass the required parameters for signing in?????
or some thing else???
I think you are intending to make auto signing kind of stuff if i am correct.
or some thing else???
I think you are intending to make auto signing kind of stuff if i am correct.
I forgot to tell you that as the HttpClient maintains the Session information you need not provide the signin info again and again (almost similar like in the case of the Browser). So HttpClient is a browser and all the PostMethod/GetMethod are the form submits and page requests respectively that u will be making to the site.
ASKER
Wow - Thanks for the prompt response!
Shivaspk,
In a nut shell what I am trying to do is download all the auction information into a database. For the first link (below) there is no log in required and I simply parse the data and write to a db. For the (2) link a login is required and this is the point that I am stuck on.
(1)http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193
(2)http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193
Gauravkrtomar,
Thanks for the info. I am going to review the web site and work out how to implement your code. I am using JBuilder 9 Enterprise to develop this application and need to work out how to install the open-source project. I also need to work out how to parse it. Any tips would be most welcome.
Cheers
Shivaspk,
In a nut shell what I am trying to do is download all the auction information into a database. For the first link (below) there is no log in required and I simply parse the data and write to a db. For the (2) link a login is required and this is the point that I am stuck on.
(1)http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=4451836193
(2)http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193
Gauravkrtomar,
Thanks for the info. I am going to review the web site and work out how to implement your code. I am using JBuilder 9 Enterprise to develop this application and need to work out how to install the open-source project. I also need to work out how to parse it. Any tips would be most welcome.
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow.... I am getting somewhere fast. I have successfully implemented the Apache code that you suggested and the following code works:
HttpClient client = new HttpClient();
PostMethod loginMethod = new PostMethod("https://signin.ebay.co.uk/ws/eBayISAPI.dll?co_partnerid=2&siteid=3&UsingSSL=1");
loginMethod.addParameter(" userid", "expertsexchangetest");
loginMethod.addParameter(" pass", "experts123");
GetMethod method = new GetMethod("http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193");
try
{
client.executeMethod(login Method);
System.out.println("authen ticaed..." );
client.executeMethod(metho d);
System.out.println("succes sful");
}
catch (Exception ex)
{
ex.printStackTrace();
}
I have a couple of questions though:
1) The code is printing out the following log text: how can I disable this. Some people who will be using this product have 20,000 auctions and it is best not to have the logging.
-------------------------- ---------- ---------- ----------
13-Apr-2006 15:11:24 org.apache.commons.httpcli ent.HttpMe thodBase readResponse
INFO: Discarding unexpected response: HTTP/1.1 100 Continue
13-Apr-2006 15:11:24 org.apache.commons.httpcli ent.HttpMe thodDirect or isRedirectNeeded
INFO: Redirect requested but followRedirects is disabled
13-Apr-2006 15:11:24 org.apache.commons.httpcli ent.Simple HttpConnec tionManage r getConnectionWithTimeout
WARNING: SimpleHttpConnectionManage r being used incorrectly. Be sure that HttpMethod.releaseConnecti on() is always called and that only one thread and/or method is using this connection manager at a time.
authenticaed...
successful
2) Parsing. I have already written a class that uses BufferedReader to parse the code. I know this is ugly and hard core, however it works. How can I output the source code of the GetMethod to the BufferedReader or to a simple String. It would be simpler/quicker than rewriting the code using http://tidy.sourceforge.net/
THANKS THANKS AND THANKS for all your help!
HttpClient client = new HttpClient();
PostMethod loginMethod = new PostMethod("https://signin.ebay.co.uk/ws/eBayISAPI.dll?co_partnerid=2&siteid=3&UsingSSL=1");
loginMethod.addParameter("
loginMethod.addParameter("
GetMethod method = new GetMethod("http://offer.ebay.co.uk/ws/eBayISAPI.dll?ViewBidsLogin&item=4451836193");
try
{
client.executeMethod(login
System.out.println("authen
client.executeMethod(metho
System.out.println("succes
}
catch (Exception ex)
{
ex.printStackTrace();
}
I have a couple of questions though:
1) The code is printing out the following log text: how can I disable this. Some people who will be using this product have 20,000 auctions and it is best not to have the logging.
--------------------------
13-Apr-2006 15:11:24 org.apache.commons.httpcli
INFO: Discarding unexpected response: HTTP/1.1 100 Continue
13-Apr-2006 15:11:24 org.apache.commons.httpcli
INFO: Redirect requested but followRedirects is disabled
13-Apr-2006 15:11:24 org.apache.commons.httpcli
WARNING: SimpleHttpConnectionManage
authenticaed...
successful
2) Parsing. I have already written a class that uses BufferedReader to parse the code. I know this is ugly and hard core, however it works. How can I output the source code of the GetMethod to the BufferedReader or to a simple String. It would be simpler/quicker than rewriting the code using http://tidy.sourceforge.net/
THANKS THANKS AND THANKS for all your help!
>>How can I output the source code of the GetMethod to the BufferedReader or to a simple String. It would be simpler/quicker than rewriting the code using http://tidy.sourceforge.net/
U can use getMethod.getResponseBodyA sStream()
or getMethod.getResponseBodyA sString().
for setting the logging off try:-
System.setProperty("org.ap ache.commo ns.logging .Log", "org.apache.commons.loggin g.impl.NoO pLog");
U can use getMethod.getResponseBodyA
or getMethod.getResponseBodyA
for setting the logging off try:-
System.setProperty("org.ap
ASKER
thanks again for all your help. Your recommendations have worked. The issue that I am having now is that with the fact that the Log On is via SSL.
Therefore the logon is not successful and the reading of the (2) link is redirecting back to the logon screen.
Trying to fix it.
Therefore the logon is not successful and the reading of the (2) link is redirecting back to the logon screen.
Trying to fix it.
ASKER
hmmm. puzzling... I tried simply this:
HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(h ttpget);
System.out.println(httpget .getStatus Line());
}
catch (Exception exe)
{
exe.printStackTrace();
}
finally {
httpget.releaseConnection( );
}
And get this error
javax.net.ssl.SSLHandshake Exception: java.security.cert.Certifi cateExcept ion: CA certificate does not include basic constraints extension
at com.sun.net.ssl.internal.s sl.BaseSSL SocketImpl .a(DashoA6 275)
HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("https://www.verisign.com/");
try {
httpclient.executeMethod(h
System.out.println(httpget
}
catch (Exception exe)
{
exe.printStackTrace();
}
finally {
httpget.releaseConnection(
}
And get this error
javax.net.ssl.SSLHandshake
at com.sun.net.ssl.internal.s
http://jakarta.apache.org/commons/httpclient/sslguide.html
Look at the above link. It has all the details about how to connect to secure HTTP communication over SSL.
Look at the above link. It has all the details about how to connect to secure HTTP communication over SSL.
haha I just noticed expertsexchange is expert sex change!!! hahaha! funny never saw that before :D
http://jakarta.apache.org/commons/httpclient/
Using this u can do whatever u can do using a browser. It maintains Sessions as well, thus making it feasible to use Signin on sites.
U can do something as follows:-
HttpClient client = new HttpClient();
GetMethod method = new GetMethod("http://www.xyz.com");
PostMethod loginMethod = new PostMethod(
"http://www.xyz.com/login");
postMethod.addParameter("u
postMethod.addParameter("p
GetMethod anotherMethod = new GetMethod(
"http://www.xyz.com/dosomething");
try {
client.executeMethod(metho
System.out.println("starte
client.executeMethod(login
System.out.println("authen
client.executeMethod(anoth
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
I think this will solve ur problem.