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

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

我想知道如果采用POST方式傳參這段代碼該怎么改?

我想知道如果采用POST方式傳參這段代碼該怎么改?

茅侃侃 2023-02-17 21:17:31
在 WinForm 用下面的方法可以打開頁面并同時通過 GET 傳參實現自動登錄,string s = "http://www.xxx.com/send.aspx?user=aaa&pass=bbb";System.Diagnostics.Process.Start(s)
查看完整描述

1 回答

?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

可以用HttpWebRequest和HttpWebResponse

或者WebRequest和WebResponse


//調用方法Dictionary<stringstring> postData = new Dictionary<stringstring>();postData.Add("user""aaa");postData.Add("pass""bbb"); GetPageByPost("http://www.xxx.com/send.aspx", postData, Encoding.UTF8); /// <summary>/// 以 Post 方式提交網頁數據,獲得服務器返回的數據/// </summary>/// <param name="url"> Url </param>/// <param name="postData">Post 數據</param>/// <param name="encoder">網頁編碼</param>/// <returns>服務器返回的數據</returns>public string GetPageByPost(string url, Dictionary<stringstring> postData, Encoding encoder){    string html = "";     HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);    webReq.Method = "POST";     Stream reqStream = null;    if (postData != null && postData.Count > 0) {        StringBuilder sb = new StringBuilder();        foreach (KeyValuePair<stringstring> kv in postData) {            sb.Append(HttpUtility.UrlEncode(kv.Key));            sb.Append("=");            sb.Append(HttpUtility.UrlEncode(kv.Value));            sb.Append("&");        }         byte[] data = Encoding.UTF8.GetBytes(sb.ToString().TrimEnd('&'));         webReq.ContentType = ContentType;        webReq.ContentLength = data.Length;        reqStream = webReq.GetRequestStream();        reqStream.Write(data, 0, data.Length);    }     HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();    Stream stream = webResp.GetResponseStream();    StreamReader sr = new StreamReader(stream, encoder);    html = sr.ReadToEnd();     sr.Close();    stream.Close();     if (reqStream != null) {        reqStream.Close();    }     return html;}


查看完整回答
反對 回復 2023-02-20
  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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