• 大小: 88KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: Winform  C#  

资源简介

可以参考教程www.crifan.com/emulate_login_website_using_csharp WinformC# 模拟登陆百度 HttpWebRequest的应用 详细的代码和注释 可以充分了解HttpWebRequest 操作网站 操作Cookie的过程和方法 可以扩展为很多的应用开发,比如百度文库财富自动获取、贴吧一键签到、管理;其他网站的一些功能开发;接口的开发、网页的抓取等等。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.IO;
using System.Text.Regularexpressions;
using System.Web;

namespace emulateLoginBaidu
{
    ///
    ///Modified by you21g
    ///Email:do21g@qq.com
    ///QQ:854450055
    ///
    public partial class frmEmulateLoginBaidu : Form
    {
        CookieCollection curCookies = null;

        string codeString = ““;

        bool gotCookieBaiduid extractTokenValueOK loginBaiduOk;

        public frmEmulateLoginBaidu()
        {
            InitializeComponent();
        }

        private void frmEmulateLoginBaidu_Load(object sender EventArgs e)
        {
            //init
            curCookies = new CookieCollection();
            gotCookieBaiduid = false;
            extractTokenValueOK = false;
            loginBaiduOk = false;
        }

        /******************************************************************************
        functions in crifanLib.cs
        *******************************************************************************/

        //quote the input dict values
        //note: the return result for first para no ‘&‘
        public string quoteParas(Dictionary paras)
        {
            string quotedParas = ““;
            bool isFirst = true;
            string val = ““;
            foreach (string para in paras.Keys)
            {
                if (paras.TryGetValue(para out val))
                {
                    if (isFirst)
                    {
                        isFirst = false;
                        quotedParas += para + “=“ + HttpUtility.UrlPathEncode(val);
                    }
                    else
                    {
                        quotedParas += “&“ + para + “=“ + HttpUtility.UrlPathEncode(val);
                    }
                }
                else
                {
                    break;
                }
            }

            return quotedParas;
        }

        /******************************************************************************
        Demo emulate login baidu related functions
        *******************************************************************************/

        private void btnGetBaiduid_Click(object sender EventArgs e)
        {
            //http://www.baidu.com/
            string baiduMainUrl = txbBaiduMainUrl.Text;
            //generate http request
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baiduMainUrl);

            //add follow code to handle cookies
            req.CookieContainer = new CookieContainer();
            req.CookieContainer.Add(curCookies);

            req.Method = “GET“;
            //use request to get response
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-07-05 17:22  emulateLoginBaidu\
     目录           0  2012-11-07 14:35  emulateLoginBaidu\emulateLoginBaidu\
     文件         893  2012-11-07 14:23  emulateLoginBaidu\emulateLoginBaidu.sln
     文件       21504  2012-11-07 16:52  emulateLoginBaidu\emulateLoginBaidu.suo
     文件       24576  2013-07-06 15:09  emulateLoginBaidu\emulateLoginBaidu.v11.suo
     文件         117  2012-11-07 14:24  emulateLoginBaidu\emulateLoginBaidu\app.config
     目录           0  2012-11-07 14:23  emulateLoginBaidu\emulateLoginBaidu\bin\
     目录           0  2013-07-05 17:23  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\
     文件       30720  2013-07-06 13:16  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.exe
     文件         117  2012-11-07 14:24  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.exe.config
     文件       34304  2013-07-06 13:16  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.pdb
     文件       21472  2013-07-06 13:17  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.vshost.exe
     文件         117  2012-11-07 14:24  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.vshost.exe.config
     文件         490  2012-06-06 02:06  emulateLoginBaidu\emulateLoginBaidu\bin\Debug\emulateLoginBaidu.vshost.exe.manifest
     目录           0  2012-11-07 14:23  emulateLoginBaidu\emulateLoginBaidu\bin\Release\
     文件        4286  2012-11-07 14:34  emulateLoginBaidu\emulateLoginBaidu\crifan.ico
     文件        2038  2012-11-07 14:33  emulateLoginBaidu\emulateLoginBaidu\crifan.png
     文件        3848  2012-11-07 16:02  emulateLoginBaidu\emulateLoginBaidu\emulateLoginBaidu.csproj
     文件       13486  2013-07-10 11:32  emulateLoginBaidu\emulateLoginBaidu\frmEmulateLoginBaidu.cs
     文件       19452  2013-07-06 12:49  emulateLoginBaidu\emulateLoginBaidu\frmEmulateLoginBaidu.Designer.cs
     文件       12549  2013-07-06 12:49  emulateLoginBaidu\emulateLoginBaidu\frmEmulateLoginBaidu.resx
     目录           0  2012-11-07 14:23  emulateLoginBaidu\emulateLoginBaidu\obj\
     目录           0  2012-11-07 14:23  emulateLoginBaidu\emulateLoginBaidu\obj\x86\
     目录           0  2013-07-06 13:16  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\
     文件        1229  2013-07-06 10:36  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6350  2013-07-05 17:22  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件        1044  2013-07-06 13:17  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\emulateLoginBaidu.csproj.FileListAbsolute.txt
     文件         862  2013-07-06 12:51  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\emulateLoginBaidu.csproj.GenerateResource.Cache
     文件        1447  2013-07-06 12:43  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\emulateLoginBaidu.csprojResolveAssemblyReference.cache
     文件       30720  2013-07-06 13:16  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\emulateLoginBaidu.exe
     文件        4852  2013-07-06 12:51  emulateLoginBaidu\emulateLoginBaidu\obj\x86\Debug\emulateLoginBaidu.frmEmulateLoginBaidu.resources
............此处省略11个文件信息

评论

共有 条评论