我正在使用此代码通过 POST 请求登录网站:
HttpWebRequest httpWReq =
(HttpWebRequest)WebRequest.Create(@"http:\\domain.com\page.asp");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "username=user";
postData += "&password=pass";
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data,0,data.Length);
}
HttpWebResponse response = (HttpWebResponse)HttpWReq.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
使用 C# 控制台应用程序创建 HTTP 发布请求并接收响应
它工作正常,我得到 html 字符串作为响应,告诉我我已登录。但现在我想例如在不同的 url 下获取我的个人资料数据。例如,我使用“www.mywebsite.com/login”登录,第二个 url 是“www.mywebsite.com/myprofile”。我可以从第二个网址获取内容吗?当然我只能在登录后才能看到这个配置文件数据。