使用WebClient 获得网页内容或提交请求
生活随笔
收集整理的這篇文章主要介紹了
使用WebClient 获得网页内容或提交请求
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
WebClient 提供的向 URI 標(biāo)識的資源發(fā)送數(shù)據(jù)和從 URI 標(biāo)識的資源接收數(shù)據(jù)的公共方法。
使用時(shí)需要將捕捉到的Http頭部放入Headers中。(捕獲http可以使用HttpWatch)
WebClient wc = new WebClient();wc.Credentials = new NetworkCredential(username, password); //對于需要登錄的網(wǎng)站設(shè)置驗(yàn)證信息
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string content = wc.DownloadString(url); // 獲得內(nèi)容
string postString = "name=peter&age=24";
byte[] postData = Encoding.ASCII.GetBytes(postString);
byte[] responseArray = wc.UploadData(url, postData); // 提交數(shù)據(jù)
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/Peter-Zhang/archive/2011/09/17/2179549.html
總結(jié)
以上是生活随笔為你收集整理的使用WebClient 获得网页内容或提交请求的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 养成一个SQL好习惯带来一笔大财富
- 下一篇: obj.toSource()