Java Orkut登录

我想在java中使用ORKUT( http://www.ORKUT.com )主页的页面源。

但它需要在访问ORKUT的任何页面之前登录到ORKUT。 我该怎么做。 它不应该介于两者之间的浏览器

您应该查看Commons HTTP Client 。 有了它,您可以发送带有登录数据的POST请求,然后使用会话ID进行进一步处理。

如果你不介意阅读C#代码:

string orkutSite = "http://www.orkut.com/Login.aspx"; // enter correct address string formPage = ""; string afterLoginPage = ""; // Get postback data and cookies CookieContainer cookies = new CookieContainer(); HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(orkutSite); getRequest.CookieContainer = cookies; getRequest.Method = "GET"; HttpWebResponse form = (HttpWebResponse)getRequest.GetResponse(); using (StreamReader response = new StreamReader(form.GetResponseStream(), Encoding.UTF8)) { formPage = response.ReadToEnd(); } Dictionary inputs = new Dictionary(); inputs.Add("__EVENTTARGET", ""); inputs.Add("__EVENTARGUMENT", ""); foreach (Match input in Regex.Matches(formPage, @".*?)"".*?(?:value=""(?.*?)"".*?)? />", RegexOptions.IgnoreCase | RegexOptions.ECMAScript)) { inputs.Add(input.Groups["name"].Value, input.Groups["value"].Value); } inputs["username"] = "xxxxx"; // *please*, check for \\ inputs["password"] = "yyyyy"; // correct field names \\ byte[] buffer = Encoding.UTF8.GetBytes( String.Join("&", Array.ConvertAll, string>( inputs.ToArray(), delegate(KeyValuePair item) { return item.Key + "=" + HttpUtility.UrlEncode(item.Value); }))); HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create(orkutSite); postRequest.CookieContainer = cookies; postRequest.Method = "POST"; postRequest.ContentType = "application/x-www-form-urlencoded"; // send username/password using (Stream stream = postRequest.GetRequestStream()) { stream.Write(buffer, 0, buffer.Length); } // get response from login page using (StreamReader reader = new StreamReader( postRequest.GetResponse().GetResponseStream(), Encoding.UTF8)) { afterLoginPage = reader.ReadToEnd(); } 

有两种方法:

1)购买Octazen,它将为您做到这一点,并在每次Orkut改变某些东西时保持库更新。

2)使用watir来劫持浏览器。

使用HTTP客户端就像在水下用拳击手套固定手表一样。 它不支持JS,你必须通过cookie,解析等方式工作。