亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C#模擬登錄

C#模擬登錄

阿波羅的戰車 2018-12-07 13:30:41
1.自己設計的一個登錄頁面,兩個TextBox(txtName,txtPwd)框和一個Button,Button事件中設置( protected void Button1_Click(object sender, EventArgs e) { if (txtName.Text == "fxl" && txtPwd.Text == "123") { Response.Redirect("Main.aspx"); } } ) 2.添加一個控制臺程序: ? using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Web;using System.IO;using System.Collections;namespace 模擬登錄{ class Program { public static CookieContainer cc = new CookieContainer(); static void Main(string[] args) { CookieContainer cc = new CookieContainer();//this is for keep the Session and Cookie Hashtable param = new Hashtable();//this is for keep post data. //這個地址是我自己IIS上的地址 string urlLogin = "http://www.my.com/CS.aspx"; param.Add("txtName", "fxl"); param.Add("txtPwd", "123"); string result = PostAndGetHTML(urlLogin,ref cc, param); Console.WriteLine(result); } public static string PostAndGetHTML(string targetURL,ref CookieContainer cc, Hashtable param) { string formData = ""; foreach (DictionaryEntry de in param) { formData += de.Key.ToString() + "=" + de.Value.ToString()+"&"; } if(formData.Length>0) formData = formData.Substring(0, formData.Length - 1); //remove last '&' ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(formData); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetURL); request.Method = "POST"; //post request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)"; Stream newStream = request.GetRequestStream(); newStream.Write(data, 0, data.Length); newStream.Close(); request.CookieContainer = cc; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); cc.Add(response.Cookies); Stream stream = response.GetResponseStream(); string result = new StreamReader(stream, System.Text.Encoding.UTF8).ReadToEnd(); return result; } }} 問題1.但是獲取的源代碼總是登錄頁面的,請大家看看怎么才能獲得登錄后頁面的源代碼 2.POST數據用不用加上Button1這個參數,我是使用Firefox中的firebug獲取頁面的POST信息的
查看完整描述

3 回答

?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

怎么博客園的博問不能收藏呢,Mark一下

查看完整回答
反對 回復 2019-01-21
?
手掌心

TA貢獻1942條經驗 獲得超3個贊

Mark,Test!

查看完整回答
反對 回復 2019-01-21
  • 3 回答
  • 0 關注
  • 340 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號