C# 使用curl登录到百度空间中

 /// <summary>
    /// 使用CURL 登录 百度
    /// </summary>
public class Program
    {
      /// <summary>
      /// 使用CURL 登录 百度
      /// 1: curl -D 登录之后保存cookie的文件.txt -d "username=Test_CURL&password=123456" https://passport.baidu.com/?login
      /// 2: curl -D 保存上次的Cookie信息.txt -b 上次的cookie信息.txt http://passport.baidu.com/
      /// </summary>
      static void TestMyCurl()
      {
          string curlPath = @"f:/curl/curl-7.17.0-win32-ssl/curl-7.17.0";
          string cookie1 = "LoginCookie.txt";
          string cookie2 = "SaveCookie.txt";
          ProcessStartInfo   Info   =   new ProcessStartInfo();  
          Process   Proc   =   new Process();
          Info.FileName = "cmd.exe";
         
          Info.Arguments = "dir "+curlPath;

          Info.UseShellExecute = false;
          Info.RedirectStandardInput = true;
          Info.RedirectStandardOutput = true;
          Info.RedirectStandardError = true;
          Info.CreateNoWindow = false;
          Proc = System.Diagnostics.Process.Start(Info);
          //到指定的目录
          Proc.StandardInput.WriteLine("cd "+curlPath);


          //开始登录 1:curl -D cookie0001.txt -d "username=用户名&password=123456" https://passport.baidu.com/?login
          Proc.StandardInput.WriteLine("curl -D " + cookie1 + " -d /"username=Test_CURL&password=123456/" https://passport.baidu.com/?login");
          //第二部登录到百度个人信息中心 2:curl -D cookie0002.txt -b cookie0001.txt http://passport.baidu.com/center
          Proc.StandardInput.WriteLine("curl -D "+cookie2+" -b "+cookie1+" http://passport.baidu.com/center");
          Proc.StandardInput.WriteLine("exit");
          string strGetString = Proc.StandardOutput.ReadToEnd();
          Console.WriteLine(strGetString);
          Debug.WriteLine(strGetString);
          Console.ReadLine();
          Proc.WaitForExit();
      }

        static void Main(string[] args)
        {
            TestMyCurl();
        }
    }

 

---------------------

参考资料:

http://www.cnblogs.com/csdn/articles/190121.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值