http://wanghao29791.webk.datasir.com/code.txt
以上是httpwebrequest登陆了阿里妈妈.程序以及代码。
现在遇到的问题是这样的。
大家看看所有分类。
我现在将这些分类分析到下面list里。当点击list里面时,转到这页面。
我解决不了,很是头疼。哪位高人给看看呗
5 个解决方案
#1
你的代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;
public partial class analyse_sort : System.Web.UI.Page
{
protected CookieContainer myCookieContainer = new CookieContainer();
private void Page_Load(object sender, System.EventArgs e)
{
string strReContent = string.Empty;
//登录
strReContent = PostLogin("http://www.alimama.com/membersvc/member/login.htm", "action=MembersAction&event_submit_do_login=true&forward=&query_string=&_fmm.l._0.l=wanghao2980528@126.com&originalLogpasswd=eaa870f75edce9f&_fmm.l._0.lo=eaa870f75edce9fe0f8ae36442e3e450&remember_password=true&dologin=", "http://www.alimama.com/membersvc/member/login.htm");
//获取页面
//strReContent = GetPage("http://www.alimama.com/membersvc/my.htm", "http://www.alimama.com/membersvc/member/login.htm");
strReContent = GetPage("http://taoke.alimama.com/spreader/search_auction.htm", "http://www.alimama.com/membersvc/member/login.htm");
//可以对获得的内容进行处理:strReContent
Response.Write(strReContent);
//Response.Write();
//Console.WriteLine("Cookie is:" + cookieHeader);
}
/// <summary>
/// 功能描述:模拟登录页面,提交登录数据进行登录,并记录Header中的cookie
/// </summary>
/// <param name="strURL">登录数据提交的页面地址</param>
/// <param name="strArgs">用户登录数据</param>
/// <param name="strReferer">引用地址</param>
/// <returns>可以返回页面内容或不返回</returns>
public string PostLogin(string strURL, string strArgs, string strReferer)
{
string strResult = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
myHttpWebRequest.AllowAutoRedirect = false;
//myHttpWebRequest.AllowAutoRedirect = true;
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
myHttpWebRequest.Referer = strReferer;
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.Method = "POST";
//CookieCollection myCookies = null;
myHttpWebRequest.CookieContainer = myCookieContainer;
string domain = @".alimama.com";
#region
myCookieContainer.Add(new Cookie("alimamapw", "M1RfFB1rXA0CCFYLXgcKDQMABAFVAgFQWgoLUlUBDFNYDwcAAwQ=", @"/", domain));
myCookieContainer.Add(new Cookie("ali_apache_id", "59.65.161.31.1239282013131.3", @"/", domain));
myCookieContainer.Add(new Cookie("BX", "hq8pAmqv1ncBAR hQTvSiQmW", @"/", domain));
myCookieContainer.Add(new Cookie("downMsgcookie", "show", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_359586", "1024528853298220889", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_390770", "34956299931252333004", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_631555", "26823995302777799147", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_700373", "3856573094678876978", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_731955", "15391928321610642064", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_748998", "238699383656230636", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_ss_359586", "1_1239314266_2468161947", @"/", domain));
#endregion
byte[] bytes = Encoding.UTF8.GetBytes(strArgs);
myHttpWebRequest.ContentLength = bytes.Length;
Stream requestStream = myHttpWebRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
//Console.WriteLine(response.StatusCode.ToString());
//cookieHeader = myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));
//myCookies = response.Cookies;
sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); // //utf-8
strResult = sr.ReadToEnd();
return strResult;
}
/// <summary>
/// 功能描述:在PostLogin成功登录后记录下Headers中的cookie,然后获取此网站上其他页面的内容
/// </summary>
/// <param name="strURL">获取网站的某页面的地址</param>
/// <param name="strReferer">引用的地址</param>
/// <returns>返回页面内容</returns>
public string GetPage(string strURL, string strReferer)
{
string strResult = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
myHttpWebRequest.ContentType = "text/html";
myHttpWebRequest.Method = "GET";
myHttpWebRequest.Referer = strReferer;
//myHttpWebRequest.Headers.Add("cookie:" + cookieHeader);
myHttpWebRequest.CookieContainer = myCookieContainer;
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); // //utf-8
strResult = sr.ReadToEnd();
return strResult;
}
}
#2
什么是“这些分类分析到下面list里”?
是不是你list里是参数,类似于dropdownlist,选中后在事件中把选中的值作为参数传到你这个页上呀?
ps:analyse_sort.aspx 页面打不开
是不是你list里是参数,类似于dropdownlist,选中后在事件中把选中的值作为参数传到你这个页上呀?
ps:analyse_sort.aspx 页面打不开
#3
1.页面可以打开。
2。你运行一下代码。或者看一下那页面就知道什么问题了
2。你运行一下代码。或者看一下那页面就知道什么问题了
#4
蹭点分~
#5
无论点什么都往那个页面跳,而且那个页面的路径还是不对的!
#1
你的代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;
public partial class analyse_sort : System.Web.UI.Page
{
protected CookieContainer myCookieContainer = new CookieContainer();
private void Page_Load(object sender, System.EventArgs e)
{
string strReContent = string.Empty;
//登录
strReContent = PostLogin("http://www.alimama.com/membersvc/member/login.htm", "action=MembersAction&event_submit_do_login=true&forward=&query_string=&_fmm.l._0.l=wanghao2980528@126.com&originalLogpasswd=eaa870f75edce9f&_fmm.l._0.lo=eaa870f75edce9fe0f8ae36442e3e450&remember_password=true&dologin=", "http://www.alimama.com/membersvc/member/login.htm");
//获取页面
//strReContent = GetPage("http://www.alimama.com/membersvc/my.htm", "http://www.alimama.com/membersvc/member/login.htm");
strReContent = GetPage("http://taoke.alimama.com/spreader/search_auction.htm", "http://www.alimama.com/membersvc/member/login.htm");
//可以对获得的内容进行处理:strReContent
Response.Write(strReContent);
//Response.Write();
//Console.WriteLine("Cookie is:" + cookieHeader);
}
/// <summary>
/// 功能描述:模拟登录页面,提交登录数据进行登录,并记录Header中的cookie
/// </summary>
/// <param name="strURL">登录数据提交的页面地址</param>
/// <param name="strArgs">用户登录数据</param>
/// <param name="strReferer">引用地址</param>
/// <returns>可以返回页面内容或不返回</returns>
public string PostLogin(string strURL, string strArgs, string strReferer)
{
string strResult = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
myHttpWebRequest.AllowAutoRedirect = false;
//myHttpWebRequest.AllowAutoRedirect = true;
myHttpWebRequest.KeepAlive = true;
myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
myHttpWebRequest.Referer = strReferer;
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
myHttpWebRequest.Method = "POST";
//CookieCollection myCookies = null;
myHttpWebRequest.CookieContainer = myCookieContainer;
string domain = @".alimama.com";
#region
myCookieContainer.Add(new Cookie("alimamapw", "M1RfFB1rXA0CCFYLXgcKDQMABAFVAgFQWgoLUlUBDFNYDwcAAwQ=", @"/", domain));
myCookieContainer.Add(new Cookie("ali_apache_id", "59.65.161.31.1239282013131.3", @"/", domain));
myCookieContainer.Add(new Cookie("BX", "hq8pAmqv1ncBAR hQTvSiQmW", @"/", domain));
myCookieContainer.Add(new Cookie("downMsgcookie", "show", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_359586", "1024528853298220889", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_390770", "34956299931252333004", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_631555", "26823995302777799147", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_700373", "3856573094678876978", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_731955", "15391928321610642064", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_bc_748998", "238699383656230636", @"/", domain));
myCookieContainer.Add(new Cookie("ystat_ss_359586", "1_1239314266_2468161947", @"/", domain));
#endregion
byte[] bytes = Encoding.UTF8.GetBytes(strArgs);
myHttpWebRequest.ContentLength = bytes.Length;
Stream requestStream = myHttpWebRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
//Console.WriteLine(response.StatusCode.ToString());
//cookieHeader = myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));
//myCookies = response.Cookies;
sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); // //utf-8
strResult = sr.ReadToEnd();
return strResult;
}
/// <summary>
/// 功能描述:在PostLogin成功登录后记录下Headers中的cookie,然后获取此网站上其他页面的内容
/// </summary>
/// <param name="strURL">获取网站的某页面的地址</param>
/// <param name="strReferer">引用的地址</param>
/// <returns>返回页面内容</returns>
public string GetPage(string strURL, string strReferer)
{
string strResult = "";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
myHttpWebRequest.ContentType = "text/html";
myHttpWebRequest.Method = "GET";
myHttpWebRequest.Referer = strReferer;
//myHttpWebRequest.Headers.Add("cookie:" + cookieHeader);
myHttpWebRequest.CookieContainer = myCookieContainer;
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
response = (HttpWebResponse)myHttpWebRequest.GetResponse();
sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312")); // //utf-8
strResult = sr.ReadToEnd();
return strResult;
}
}
#2
什么是“这些分类分析到下面list里”?
是不是你list里是参数,类似于dropdownlist,选中后在事件中把选中的值作为参数传到你这个页上呀?
ps:analyse_sort.aspx 页面打不开
是不是你list里是参数,类似于dropdownlist,选中后在事件中把选中的值作为参数传到你这个页上呀?
ps:analyse_sort.aspx 页面打不开
#3
1.页面可以打开。
2。你运行一下代码。或者看一下那页面就知道什么问题了
2。你运行一下代码。或者看一下那页面就知道什么问题了
#4
蹭点分~
#5
无论点什么都往那个页面跳,而且那个页面的路径还是不对的!