Return-Path: Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@www.apache.org Received: (qmail 56137 invoked from network); 30 Apr 2004 14:06:38 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 30 Apr 2004 14:06:38 -0000 Received: (qmail 88699 invoked by uid 500); 30 Apr 2004 14:06:31 -0000 Delivered-To: apmail-jakarta-commons-httpclient-dev-archive@jakarta.apache.org Received: (qmail 88677 invoked by uid 500); 30 Apr 2004 14:06:31 -0000 Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Commons HttpClient Project" Reply-To: "Commons HttpClient Project" Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 88658 invoked from network); 30 Apr 2004 14:06:31 -0000 Received: from unknown (HELO phexchange.nbsi.net) (66.45.112.9) by daedalus.apache.org with SMTP; 30 Apr 2004 14:06:31 -0000 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: Yahoo login with Httpclient X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Date: Fri, 30 Apr 2004 10:06:32 -0400 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Yahoo login with Httpclient Thread-Index: AcQuWsUUQgXmDFBAQ8iyIYvqaQTheQAYLjUw From: "Min (Frank) Ni" To: "Commons HttpClient Project" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hello Mike: According to your advice, I changed the code to look like the following, = but I am getting "Invalid Password" error. I used the Id and password = from the IE browser and it logged me in.=20 I noticed in your loginMD5(), there are two GetMethod()'s, should the = second one be "PostMethod()" ? I'm not familiar with HttpClient enough = to be sure. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.security.MessageDigest; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; //import org.apache.commons.httpclient.params.HttpMethodParams; public class YahooLogin { private HttpClient client; =20 private String password =3D "javatest"; private String login =3D "javamr"; =20 private String host; private String u; private String challenge; =20 public YahooLogin() { client =3D new HttpClient(); =20 // = client.getParams().setParameter(HttpMethodParams.USER_AGENT, = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/124 (KHTML, = like Gecko) Safari/125.1"); } =20 public void parseResponse(InputStream is) throws Exception { BufferedReader reader =3D new BufferedReader(new = InputStreamReader(is)); String line =3D null; =20 Pattern uP =3D Pattern.compile(".*name=3D\"\\.u\" = value=3D\"([^\"]+)\".*"); Pattern challengeP =3D Pattern.compile(".*name=3D\"\\.challenge\" = value=3D\"([^\"]+)\".*"); Pattern hostP =3D Pattern.compile(".*method=3Dpost = action=3D\"([^\"]+)\".*"); =20 while ((line =3D reader.readLine()) !=3D null) { Matcher uM =3D uP.matcher(line); Matcher challengeM =3D challengeP.matcher(line); Matcher hostM =3D hostP.matcher(line); =20 if (uM.matches()) { u =3D uM.group(1); } if (challengeM.matches()) { challenge =3D challengeM.group(1); } if (hostM.matches()) { host =3D hostM.group(1); } } =20 System.out.println("u=3D" + u); System.out.println("host=3D" + host); System.out.println("challenge=3D" + challenge); } =20 public void loginNormal() throws Exception { =20 GetMethod get =3D new = GetMethod("http://login.yahoo.com/config/login?.src=3Dwww&.done=3Dhttp://= www.yahoo.com"); =20 get.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC = Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1"); client.executeMethod(get); =20 parseResponse(get.getResponseBodyAsStream()); =20 NameValuePair[] pairs =3D { new NameValuePair("login", login), new NameValuePair("password", password), new NameValuePair(".tries", "1"), new NameValuePair(".src", "www"), new NameValuePair(".md5", ""), new NameValuePair(".hash", ""), new NameValuePair(".js", ""), new NameValuePair(".last", ""), new NameValuePair(".promo", ""), new NameValuePair(".intl", "us"), new NameValuePair(".bypass", ""), new NameValuePair(".partner", ""), new NameValuePair(".u", u), new NameValuePair(".v", "0"), new NameValuePair(".challenge", challenge), new NameValuePair(".yplus", ""), new NameValuePair(".emailCode", ""), new NameValuePair("pkg", ""), new NameValuePair("stepid", ""), new NameValuePair(".ev", ""), new NameValuePair("hasMsgr", "0"), new NameValuePair(".chkP", "Y"), new NameValuePair(".done", "http://www.yahoo.com"), new NameValuePair(".persistent", "y"), }; =20 PostMethod post =3D new PostMethod(host); post.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC = Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1"); =20 post.addRequestHeader("Accept", "*/*"); post.addRequestHeader("Accept-Language", "en-us, ja;q=3D0.21, = de-de;q=3D0.86, de;q=3D0.79, fr-fr;q=3D0.71, fr;q=3D0.64, = nl-nl;q=3D0.57, nl;q=3D0.50, it-it;q=3D0.43, it;q=3D0.36, = ja-jp;q=3D0.29, en;q=3D0.93, es-es;q=3D0.14, es;q=3D0.07"); post.setRequestBody(pairs); client.executeMethod(post); =20 post.getResponseBodyAsString(); } =20 public void loginMD5() throws Exception { =20 GetMethod get =3D new = GetMethod("http://login.yahoo.com/config/login?.src=3Dwww&.done=3Dhttp://= www.yahoo.com"); =20 get.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC = Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1"); =20 client.executeMethod(get); =20 parseResponse(get.getResponseBodyAsStream()); =20 MessageDigest digest =3D MessageDigest.getInstance("MD5"); digest.update(password.getBytes("US-ASCII")); =20 String hash1 =3D new String(digest.digest(), "US-ASCII"); String hash2 =3D hash1 + challenge; =20 digest.update(hash2.getBytes("US-ASCII")); String hash =3D new String(digest.digest(), "US-ASCII"); =20 NameValuePair[] pairs =3D { new NameValuePair("login", login), new NameValuePair("password", hash), new NameValuePair(".save", "1"), new NameValuePair(".tries", "1"), new NameValuePair(".src", "www"), new NameValuePair(".md5", "1"), new NameValuePair(".hash", "1"), new NameValuePair(".js", "1"), new NameValuePair(".last", ""), new NameValuePair(".promo", ""), new NameValuePair(".intl", "us"), new NameValuePair(".bypass", ""), new NameValuePair(".u", u), new NameValuePair(".v", "0"), new NameValuePair(".challenge", challenge), new NameValuePair(".yplus", ""), new NameValuePair(".emailCode", ""), new NameValuePair("pkg", ""), new NameValuePair("stepid", ""), new NameValuePair(".ev", ""), new NameValuePair("hasMsgr", "0"), new NameValuePair(".chkP", "Y"), new NameValuePair(".done", "http://www.yahoo.com"), new NameValuePair(".persistent", "y"), }; =20 get =3D new GetMethod("http://login.yahoo.com/config/login"); =20 get.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC = Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1"); get.addRequestHeader("Accept", "*/*"); get.addRequestHeader("Accept-Language", "en-us, ja;q=3D0.21, = de-de;q=3D0.86, de;q=3D0.79, fr-fr;q=3D0.71, fr;q=3D0.64, = nl-nl;q=3D0.57, nl;q=3D0.50, it-it;q=3D0.43, it;q=3D0.36, = ja-jp;q=3D0.29, en;q=3D0.93, es-es;q=3D0.14, es;q=3D0.07"); get.setQueryString(pairs); client.executeMethod(get); =20 get.getResponseBodyAsString(); } =20 public static void main(String[] args) throws Exception { =20 System.setProperty("org.apache.commons.logging.Log", = "org.apache.commons.logging.impl.SimpleLog"); = System.setProperty("org.apache.commons.logging.simplelog.showdatetime", = "true"); = System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.w= ire", "trace"); = System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.c= ommons.httpclient", "debug"); =20 new YahooLogin().loginNormal(); =20 new YahooLogin().loginMD5(); =20 } } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thanks for your kind help. Frank -----Original Message----- From: Michael Becke [mailto:becke@u.washington.edu] Sent: Thursday, April 29, 2004 10:28 PM To: Commons HttpClient Project Subject: Re: Yahoo login with Httpclient Oops. Yes, I'm using HttpClient from the HEAD branch. If you take out =20 the references to HttpMethodParams and add the following for each =20 method, it should work: method.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPC =20 Mac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1"); You can also change the user agent to something else if you like. Mike On Apr 29, 2004, at 9:54 AM, Min (Frank) Ni wrote: > Hi Mike: > > Thank you for your sample code, I tried to compile it, but got the =20 > following errors : > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > YahooLogin.java [13:1] package org.apache.commons.httpclient.params =20 > does not exist > import org.apache.commons.httpclient.params.HttpMethodParams; > ^ > YahooLogin.java [28:1] cannot find symbol > symbol : variable HttpMethodParams > location: class YahooLogin > client.getParams().setParameter(HttpMethodParams.USER_AGENT, =20 > "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/124 =20 > (KHTML, like Gecko) Safari/125.1"); > ^ > YahooLogin.java [28:1] cannot find symbol > symbol : method getParams() > location: class org.apache.commons.httpclient.HttpClient > client.getParams().setParameter(HttpMethodParams.USER_AGENT, =20 > "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/124 =20 > (KHTML, like Gecko) Safari/125.1"); > ^ > 3 errors > Errors compiling YahooLogin. > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > I have mounted "commons-httpclient-2.0.jar" and "commons-logging.jar" = > on to my project in NetBeans, Have I missed anything else that has =20 > "package org.apache.commons.httpclient.params" ? > > Frank > > -----Original Message----- > From: Michael Becke [mailto:becke@u.washington.edu] > Sent: Thursday, April 29, 2004 12:35 AM > To: Commons HttpClient Project > Subject: Re: Yahoo login with Httpclient > > > Well, I've tried a variety of things, but I cannot successfully login > to yahoo. Attached is the code that I've been using. It includes two > methods, one to simulate logging in from a browser with JavaScript > turned off, and another to simulate with JS on. Perhaps someone else > can figure it out from here. > > Mike > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: =20 > commons-httpclient-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: =20 > commons-httpclient-dev-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: = commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: = commons-httpclient-dev-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org