gpt4 book ai didi

Java Orkut 登录

转载 作者:行者123 更新时间:2023-12-01 17:40:26 24 4
gpt4 key购买 nike

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

但在访问 ORKUT 的任何页面之前,需要先登录 ORKUT。我该怎么做。中间不应该涉及浏览器

最佳答案

如果您不介意阅读 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<string, string> inputs = new Dictionary<string,string>();
inputs.Add("__EVENTTARGET", "");
inputs.Add("__EVENTARGUMENT", "");
foreach (Match input in
Regex.Matches(formPage,
@"<input.*?name=""(?<name>.*?)"".*?(?:value=""(?<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<KeyValuePair<string, string>, 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();
}

关于Java Orkut 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1525697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com