/// 使用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();
}
}
---------------------
参考资料: