Exemplo n.º 1
0
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

            // simple post - with a string
            easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,
                        "url=index%3Dstripbooks&field-keywords=Topology&Go.x=10&Go.y=10");

            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                        "Mozilla 4.0 (compatible; MSIE 6.0; Win32");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_URL,
                        "http://www.amazon.com/exec/obidos/search-handle-form/002-5928901-6229641");
            easy.SetOpt(CURLoption.CURLOPT_POST, true);

            easy.Perform();
            easy.Cleanup();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 2
0
    public static void Main(String[] args)
    {
        try
        {
            Curl.GlobalInit(CurlInitFlag.All);

            var vd = Curl.GetVersionInfo(CurlVersion.Now);
#if USE_LIBCURLSHIM
            Console.WriteLine("           Age: {0}", vd.Age);
            Console.WriteLine("Version String: {0}", vd.Version);
            Console.WriteLine("Version Number: {0}", vd.VersionNum);
            Console.WriteLine("   Host System: {0}", vd.Host);
            Console.WriteLine("Feature Bitmap: {0}", vd.Features);
            Console.WriteLine("   Ssl Version: {0}", vd.SslVersion);
            Console.WriteLine("Ssl VersionNum: {0}", vd.SSLVersionNum);
            Console.WriteLine("  LibZ Version: {0}", vd.LibZVersion);
            Console.WriteLine("  ARES Version: {0}", vd.ARes);
            Console.WriteLine("  ARES Ver Num: {0}", vd.AResNum);
            Console.WriteLine("LibIdn Version: {0}", vd.LibIdn);
            Console.WriteLine();
            Console.WriteLine("Protocols:");
            var protocols = vd.Protocols;
            foreach (var prot in protocols)
            {
                Console.WriteLine("  {0}", prot);
            }
#endif
            Curl.GlobalCleanup();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            Console.ReadLine();
        }
    }
Exemplo n.º 3
0
        public static void Main(String[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                using (var fs = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (var easy = new CurlEasy())
                    {
                        easy.ReadFunction  = OnReadData;
                        easy.ReadData      = fs;
                        easy.DebugFunction = OnDebug;
                        easy.SetOpt(CurlOption.Verbose, true);
                        easy.ProgressFunction = OnProgress;
                        easy.Url = args[1];
                        easy.SetOpt(CurlOption.UserPwd, args[2] + ":" + args[3]);
                        easy.Upload     = true;
                        easy.InfileSize = fs.Length;

                        easy.Perform();
                    }
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Exemplo n.º 4
0
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

            Easy.SSLContextFunction sf = new Easy.SSLContextFunction(OnSSLContext);
            easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);

            easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

            easy.Perform();
            easy.Cleanup();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 5
0
        public static string f_https_getTextByUrl(string url)
        {
            var dataRecorder = new EasyDataRecorder();

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_DEFAULT);
            try
            {
                using (Easy easy = new Easy())
                {
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, (Easy.WriteFunction)dataRecorder.HandleWrite);

                    Easy.SSLContextFunction sf = new Easy.SSLContextFunction(OnSSLContext);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);

                    easy.SetOpt(CURLoption.CURLOPT_URL, url);
                    //easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");
                    easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");


                    easy.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }

            string s = Encoding.UTF8.GetString(dataRecorder.Written.ToArray());

            return(s);
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                using (var curl = new CurlEasy())
                {
                    curl.Url    = "smtp://*****:*****@example.com>");
                    using (var recipients = new CurlSlist())
                    {
                        recipients.Append("<*****@*****.**>");
                        recipients.Append("<*****@*****.**>");
                        var s = recipients.Strings;
                        curl.SetOpt(CurlOption.MailRcpt, recipients.Handle);

                        curl.Perform();
                    }
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 7
0
    public static void run(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            VersionInfoData vd = Curl.GetVersionInfo(CURLversion.CURLVERSION_NOW);
            Console.WriteLine("           Age: {0}", vd.Age);
            Console.WriteLine("Version String: {0}", vd.Version);
            Console.WriteLine("Version Number: {0}", vd.VersionNum);
            Console.WriteLine("   Host System: {0}", vd.Host);
            Console.WriteLine("Feature Bitmap: {0}", vd.Features);
            Console.WriteLine("   SSL Version: {0}", vd.SSLVersion);
            Console.WriteLine("SSL VersionNum: {0}", vd.SSLVersionNum);
            Console.WriteLine("  LibZ Version: {0}", vd.LibZVersion);
            Console.WriteLine("  ARES Version: {0}", vd.ARes);
            Console.WriteLine("  ARES Ver Num: {0}", vd.AResNum);
            Console.WriteLine("LibIDN Version: {0}", vd.LibIDN);
            Console.WriteLine();
            Console.WriteLine("Protocols:");
            String[] protocols = vd.Protocols;
            foreach (String prot in protocols)
            {
                Console.WriteLine("  {0}", prot);
            }

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 8
0
    public static void Main(String[] args)
    {
        try
        {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

            Easy.SSLContextFunction sf = new Easy.SSLContextFunction(OnSSLContext);
            easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);



            easy.SetOpt(CURLoption.CURLOPT_URL, "https://dictionary.cambridge.org/grammar/british-grammar/above-or-over");
            easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

            easy.Perform();
            //easy.Cleanup();
            //easy.Dispose();

            Curl.GlobalCleanup();

            Console.WriteLine("Enter to exit ...");
            Console.ReadLine();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
 private void logQuery(object sender, DoWorkEventArgs e)
 {
     Curl.GlobalInit(CurlInitFlag.All);
     using (var easy = new CurlEasy())
     {
         String[] ar         = e.Argument as String[];
         string   postData   = "form_submitted=1&form_username="******"&form_password="******"&form_autologin=1";
         var      postLength = postData.Length;
         easy.WriteFunction += OnWriteData;
         easy.WriteData      = null;
         easy.UserAgent      = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36";
         easy.FollowLocation = true;
         easy.Url            = "https://thepilotslife.com/?";
         string   fileName = "cookie.txt";
         FileInfo f        = new FileInfo(fileName);
         easy.CookieJar     = f.FullName;
         easy.CookieFile    = f.FullName;
         easy.SslVerifyPeer = false;
         easy.CookieSession = true;
         easy.Post          = true;
         easy.PostFields    = postData;
         easy.PostFieldSize = postLength;
         var code = easy.Perform();
     }
     Curl.GlobalCleanup();
 }
Exemplo n.º 10
0
        public static void Main(String[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                using (var easy = new CurlEasy())
                {
                    const string postData = "url=index%3Dstripbooks&field-keywords=Topology&Go.x=10&Go.y=10";
                    easy.WriteFunction  = OnWriteData;
                    easy.WriteData      = null;
                    easy.PostFields     = postData;
                    easy.PostFieldSize  = postData.Length;
                    easy.UserAgent      = "Mozilla 4.0 (compatible; MSIE 6.0; Win32";
                    easy.FollowLocation = true;
                    easy.Url            = "http://www.amazon.com/exec/obidos/search-handle-form/002-5928901-6229641";
                    easy.Post           = true;

                    var code = easy.Perform();
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemplo n.º 11
0
    public static void run(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            dnsLock    = new Object();
            cookieLock = new Object();

            Share share              = new Share();
            Share.LockFunction   lf  = new Share.LockFunction(OnLock);
            Share.UnlockFunction ulf = new Share.UnlockFunction(OnUnlock);
            share.SetOpt(CURLSHoption.CURLSHOPT_LOCKFUNC, lf);
            share.SetOpt(CURLSHoption.CURLSHOPT_UNLOCKFUNC, ulf);
            share.SetOpt(CURLSHoption.CURLSHOPT_SHARE,
                         CURLlockData.CURL_LOCK_DATA_COOKIE);
            share.SetOpt(CURLSHoption.CURLSHOPT_SHARE,
                         CURLlockData.CURL_LOCK_DATA_DNS);

            EasyThread et1 = new EasyThread(args[0], share);
            EasyThread et2 = new EasyThread(args[1], share);
            Thread     t1  = new Thread(new ThreadStart(et1.ThreadFunc));
            Thread     t2  = new Thread(new ThreadStart(et2.ThreadFunc));
            t1.Start();
            t2.Start();
            t1.Join();
            t2.Join();

            share.Cleanup();
            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 12
0
        private static void Main(string[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                using (var curl = new CurlEasy())
                {
                    /* This is the URL for your mailserver */
                    curl.Url = "smtp://*****:*****@example.org>");

                    /* Add two recipients, in this particular case they correspond to
                     * the To: and Cc: addressees in the header, but they could be any
                     * kind of recipient. */
                    using (var recipients = new CurlSlist())
                    {
                        recipients.Append("<*****@*****.**>");
                        recipients.Append("<*****@*****.**>");
                        curl.SetOpt(CurlOption.MailRcpt, recipients);

                        /* We're using a callback function to specify the payload (the
                         * headers and body of the message). You could just use the
                         * ReadData option to  specify a FILE pointer to read from. */
                        curl.ReadFunction = PayloadSource;
                        curl.ReadData     = new UploadContext();
                        curl.Upload       = true;

                        var res = curl.Perform();
                        if (res != CurlCode.Ok)
                        {
                            Console.WriteLine("CurlEasy.Perform() failed: " + res);
                        }
                    }

                    /* curl won't send the QUIT command until you call cleanup, so you should be
                     * able to re-use this connection for additional messages (setting
                     * CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
                     * Perform() again. It may not be a good idea to keep the
                     * connection open for a very long time though (more than a few minutes may
                     * result in the server timing out the connection), and you do want to clean
                     * up in the end.
                     */
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Exemplo n.º 13
0
 protected override bool ReleaseHandle()
 {
     if (_initialized && _available)
     {
         Curl.GlobalCleanup();
         _available = false;
     }
     return(true);
 }
Exemplo n.º 14
0
    public static void run(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            // <form action="http://mybox/cgi-bin/myscript.cgi
            //  method="post" enctype="multipart/form-data">
            MultiPartForm mf = new MultiPartForm();

            // <input name="frmUsername">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "frmUsername",
                          CURLformoption.CURLFORM_COPYCONTENTS, "testtcc",
                          CURLformoption.CURLFORM_END);

            // <input name="frmPassword">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "frmPassword",
                          CURLformoption.CURLFORM_COPYCONTENTS, "tcc",
                          CURLformoption.CURLFORM_END);

            // <input name="frmFileOrigPath">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "frmFileOrigPath",
                          CURLformoption.CURLFORM_COPYCONTENTS, args[1],
                          CURLformoption.CURLFORM_END);

            // <input name="frmFileDate">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "frmFileDate",
                          CURLformoption.CURLFORM_COPYCONTENTS, "08/01/2004",
                          CURLformoption.CURLFORM_END);

            // <input type="File" name="f1">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "f1",
                          CURLformoption.CURLFORM_FILE, args[1],
                          CURLformoption.CURLFORM_CONTENTTYPE, "application/binary",
                          CURLformoption.CURLFORM_END);

            Easy easy = new Easy();

            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
            easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

            Easy.ProgressFunction pf = new Easy.ProgressFunction(OnProgress);
            easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf);

            easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf);

            easy.Perform();
            //easy.Cleanup();
            mf.Free();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 15
0
        //curl https://pixiv.net/
        //curl: (35) schannel: failed to receive handshake, SSL/TLS connection failed

        //curl http://www.example.com/?name=www.twitter.com
        //curl: (56) Recv failure: Connection was reset

        static void Main()
        {
            try
            {
                var aResolve = new DnsClient(IPAddress.Parse("2.2.2.2"), 5000).Resolve(DomainName.Parse("pixiv.net"));
                aResolve.AnswerRecords.ForEach(Console.WriteLine);
                var bResolve = new DnsClient(IPAddress.Parse("2.2.2.2"), 5000).Resolve(DomainName.Parse("baidu.com"));
                bResolve.AnswerRecords.ForEach(Console.WriteLine);
                Curl.GlobalInit(CurlInitFlag.All);
                using (var easy = new CurlEasy())
                {
                    easy.DnsUseGlobalCache = false;
                    easy.DnsCacheTimeout   = 0;
                    //easy.Proxy = "127.0.0.1:7890";
                    easy.CaInfo = "cacert.pem";
                    //easy.SetOpt(CurlOption.DnsLocalIp4, "1.1.1.1");
                    easy.Url            = "https://pixiv.net/";
                    easy.ConnectTimeout = 5;
                    easy.Timeout        = 5;
                    easy.HeaderFunction = (buf, size, nmemb, data) => {
                        Console.Write(Encoding.UTF8.GetString(buf));
                        return(size * nmemb);
                    };
                    easy.WriteFunction = (buf, size, nmemb, data) => {
                        Console.Write(Encoding.UTF8.GetString(buf));
                        return(size * nmemb);
                    };
                    easy.Filetime = true;

                    var c = easy.Perform();
                    Console.WriteLine("Perform:" + c + (int)c);
                    Console.WriteLine("SslEngine: {0}", easy.SslEngine);
                    Console.WriteLine("Connect Time: {0}", easy.ConnectTime);
                    Console.WriteLine("Content Type: {0}", easy.ContentType);
                    Console.WriteLine("HTTP Connect Code: {0}", easy.HttpConnectCode);
                    Console.WriteLine("Name Lookup Time: {0}", easy.NameLookupTime);
                    Console.WriteLine("OS Errno: {0}", easy.OsErrno);
                    Console.WriteLine("Pretransfer time: {0}", easy.PreTransferTime);
                    Console.WriteLine("Redirect time: {0}", easy.RedirectTime);
                    Console.WriteLine("Response code: {0}", easy.ResponseCode);
                    Console.WriteLine("Ssl verification result: {0}", easy.SslVerifyResult);
                    Console.WriteLine("Start transfer time: {0}", easy.StartTransferTime);
                    Console.WriteLine("Total time: {0}", easy.TotalTime);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                Curl.GlobalCleanup();
            }

            Console.ReadKey();
        }
Exemplo n.º 16
0
        public static void Main(string[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                // <form action="http://mybox/cgi-bin/myscript.cgi
                //  method="post" enctype="multipart/form-data">
                using (var mf = new CurlHttpMultiPartForm())
                {
                    mf.AddSection(CurlFormOption.CopyName, "frmUsername",
                                  CurlFormOption.CopyContents, "testtcc",
                                  CurlFormOption.End);

                    // <input name="frmPassword">
                    mf.AddSection(CurlFormOption.CopyName, "frmPassword",
                                  CurlFormOption.CopyContents, "tcc",
                                  CurlFormOption.End);

                    // <input name="frmFileOrigPath">
                    mf.AddSection(CurlFormOption.CopyName, "frmFileOrigPath",
                                  CurlFormOption.CopyContents, args[1],
                                  CurlFormOption.End);

                    // <input name="frmFileDate">
                    mf.AddSection(CurlFormOption.CopyName, "frmFileDate",
                                  CurlFormOption.CopyContents, "08/01/2004",
                                  CurlFormOption.End);

                    // <input type="File" name="f1">
                    mf.AddSection(CurlFormOption.CopyName, "f1",
                                  CurlFormOption.File, args[1],
                                  CurlFormOption.ContentType, "application/binary",
                                  CurlFormOption.End);

                    using (var easy = new CurlEasy())
                    {
                        easy.DebugFunction    = OnDebug;
                        easy.Verbose          = true;
                        easy.ProgressFunction = OnProgress;
                        easy.Url      = args[0];
                        easy.HttpPost = mf;

                        easy.Perform();
                    }
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                WriteLine(ex);
                ReadLine();
            }
        }
Exemplo n.º 17
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Application.Run(new DocDownloadWnd());

            Curl.GlobalCleanup();
        }
Exemplo n.º 18
0
        static void post1()
        {
            URL = "https://azure.microsoft.com/en-us/cognitive-services/demo/websearchapi/";
            Console.WriteLine("POST: " + URL);
            File.WriteAllText("libcurl-post.txt", string.Empty);

            var dataRecorder = new EasyDataRecorder();

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_DEFAULT);
            try
            {
                using (Easy easy = new Easy())
                {
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, (Easy.WriteFunction)dataRecorder.HandleWrite);

                    Easy.SSLContextFunction sf = new Easy.SSLContextFunction(OnSSLContext);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);

                    //POST
                    easy.SetOpt(CURLoption.CURLOPT_URL, URL);

                    /* use a POST to fetch this */
                    //easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, 1L);
                    string coo = File.ReadAllText("cookies.txt").Trim();
                    string __RequestVerificationToken = string.Empty;
                    if (coo.Contains("__RequestVerificationToken"))
                    {
                        __RequestVerificationToken = coo.Split(new string[] { "__RequestVerificationToken" }, StringSplitOptions.None)[1].Trim();
                    }

                    /* Now specify the POST data */
                    easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, "__RequestVerificationToken=" + __RequestVerificationToken + "&Query=english+due+to+tienganh123&Market=en-us&Safesearch=Strict&freshness=");


                    easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

                    //read cookie
                    easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, "cookies.txt");

                    easy.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }
            string s = Encoding.UTF8.GetString(dataRecorder.Written.ToArray());

            //Console.WriteLine(s);
            File.WriteAllText("libcurl-post.txt", s);
            Console.WriteLine("\r\n[END-POST]");
        }
        static void Main(string[] args)
        {
            Console.WriteLine("libcurlFtpsExample...");

            const string url = "ftp://*****:*****@ftp.somesite.com/dir/";

            try
            {
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

                Easy easy = new Easy();
                if (easy != null)
                {
                    easy.SetOpt(CURLoption.CURLOPT_URL, url);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, false);
                    easy.SetOpt(CURLoption.CURLOPT_FTP_SSL, CURLftpSSL.CURLFTPSSL_TRY);

                    // For debugging will print headers to console.
                    Easy.HeaderFunction hf = new Easy.HeaderFunction(OnHeaderData);
                    easy.SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, hf);

                    // For debugging will print received data to console.
                    Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
                    easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
                    easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

                    // List directory only
                    easy.SetOpt(CURLoption.CURLOPT_FTPLISTONLY, true);

                    CURLcode code = easy.Perform();
                    if (code != CURLcode.CURLE_OK)
                    {
                        Console.WriteLine("Request failed!");
                    }

                    easy.Cleanup();
                }
                else
                {
                    Console.WriteLine("Failed to get Easy libcurl handle!");
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
            finally
            {
                Curl.GlobalCleanup();
            }
        }
 void chat_receiver(object sender, DoWorkEventArgs e)
 {
     Curl.GlobalInit(CurlInitFlag.All);
     using (var easy = new CurlEasy())
     {
         //sender session init
         sender_easy = new CurlEasy();
         sender_init();
         //sender session init END
         //receiver session init
         easy.WriteData      = null;
         easy.UserAgent      = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36";
         easy.FollowLocation = true;
         easy.Url            = "https://thepilotslife.com/chat";
         string   fileName = "cookie.txt";
         FileInfo f        = new FileInfo(fileName);
         easy.CookieJar     = f.FullName;
         easy.CookieFile    = f.FullName;
         easy.SslVerifyPeer = false;
         easy.CookieSession = true;
         easy.Perform();
         easy.WriteFunction += OnWriteData;
         easy.Url            = "https://thepilotslife.com/assets/chat-output.php";
         short i = (short)((((App)Application.Current).fetchsec * 10) / 3);
         while (true)
         {
             try
             {
                 if (i >= (short)((((App)Application.Current).fetchsec * 10) / 3))
                 {
                     Query sQuery = new Query("167.114.145.46", 7777);
                     sQuery.Send('c');
                     int      count = sQuery.Receive();
                     string[] info  = sQuery.Store(count);
                     main_worker.ReportProgress(96, info);
                     i = 0;
                 }
             }
             catch
             {
                 break;
             }
             easy.Perform();
             i++;
             System.Threading.Thread.Sleep(300);
         }
     }
     Curl.GlobalCleanup();
 }
Exemplo n.º 21
0
        public static void Main(String[] args)
        {
            try
            {
                Curl.GlobalInit(CurlInitFlag.All);

                dnsLock    = new Object();
                cookieLock = new Object();

                var urls = new[]
                {
                    "http://www.codeplex.com",
                    "http://www.yahoo.com",
                    "http://www.cnn.com",
                    "http://www.abc.com",
                    "http://www.bbc.co.uk"
                };

                using (var share = new CurlShare())
                {
                    share.LockFunction   = OnLock;
                    share.UnlockFunction = OnUnlock;
                    share.Share          = CurlLockData.Cookie;
                    share.Share          = CurlLockData.Dns;

                    var workers = new List <Thread>();
                    foreach (var url in urls)
                    {
                        var et     = new EasyThread(url, share);
                        var thread = new Thread(et.ThreadFunc);
                        workers.Add(thread);
                        thread.Start();
                    }

                    foreach (var thread in workers)
                    {
                        thread.Join();
                    }
                }

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Exemplo n.º 22
0
 public void Dispose()
 {
     try
     {
         if (this.headerArgs != null)
         {
             this.headerArgs.Clear();
         }
         this._CleanInstance();
         Curl.GlobalCleanup();
     }
     catch (Exception)
     {
     }
     GC.SuppressFinalize(this);
 }
Exemplo n.º 23
0
        private void buttonGetSource_Click(object sender, EventArgs e)
        {
            textBoxSource.Clear();
            Curl.GlobalInit(CurlInitFlag.All);

            using (var easy = new CurlEasy())
            {
                easy.AutoReferer    = true;
                easy.FollowLocation = true;
                easy.Url            = textBoxUrl.Text.Trim();
                easy.WriteFunction  = OnWriteData;
                easy.Perform();
            }

            Curl.GlobalCleanup();
        }
Exemplo n.º 24
0
        public static oResult test_http(Dictionary <string, object> request = null)
        {
            oResult rs = new oResult()
            {
                ok = false, request = request
            };

            string url = request.getValue <string>("url");

            if (string.IsNullOrWhiteSpace(url))
            {
                url = "http://localhost/";
            }

            try
            {
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

                Easy               easy = new Easy();
                StringBuilder      bi   = new StringBuilder();
                Easy.WriteFunction wf   = new Easy.WriteFunction((buf, size, nmemb, extraData) =>
                {
                    string si = Encoding.UTF8.GetString(buf);
                    bi.Append(si);
                    return(size * nmemb);
                });

                easy.SetOpt(CURLoption.CURLOPT_URL, url);
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

                easy.Perform();
                //easy.Cleanup();
                easy.Dispose();

                Curl.GlobalCleanup();

                rs.data = bi.ToString();
                rs.ok   = true;
                rs.type = DATA_TYPE.HTML_TEXT;
            }
            catch (Exception ex)
            {
                rs.error = ex.Message;
            }

            return(rs);
        }
Exemplo n.º 25
0
    public static void Execute(string requestId, COMMANDS cmd, string input, Dictionary <string, object> data)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            //string file = @"c:\test.txt";
            //File.WriteAllText(file, input, Encoding.UTF8);
            //FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
            var buf    = Encoding.UTF8.GetBytes(input);
            var stream = new MemoryStream(buf);

            string urlFTP   = data.Get <string>("ftp");
            string username = data.Get <string>("username");
            string password = data.Get <string>("password");

            Easy easy = new Easy();

            //Easy.ReadFunction rf = new Easy.ReadFunction(OnReadData);
            //easy.SetOpt(CURLoption.CURLOPT_READFUNCTION, rf);
            //easy.SetOpt(CURLoption.CURLOPT_READDATA, stream);
            easy.SetOpt(CURLoption.CURLOPT_WRITEDATA, stream);

            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
            easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

            Easy.ProgressFunction pf = new Easy.ProgressFunction(OnProgress);
            easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf);

            easy.SetOpt(CURLoption.CURLOPT_URL, urlFTP);
            easy.SetOpt(CURLoption.CURLOPT_FTPPORT, 22);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD, username + ":" + password);
            easy.SetOpt(CURLoption.CURLOPT_UPLOAD, true);
            easy.SetOpt(CURLoption.CURLOPT_INFILESIZE, stream.Length);

            easy.Perform();
            //easy.Cleanup();

            stream.Close();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
Exemplo n.º 26
0
        static void get1()
        {
            //URL = "http://httpbin.org/";
            //URL = "https://vnexpress.net/";
            URL = "https://azure.microsoft.com/en-us/services/cognitive-services/bing-web-search-api/";
            Console.WriteLine("GET: " + URL);
            File.WriteAllText("libcurl-get.txt", string.Empty);

            var dataRecorder = new EasyDataRecorder();

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_DEFAULT);
            try
            {
                using (Easy easy = new Easy())
                {
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, (Easy.WriteFunction)dataRecorder.HandleWrite);

                    /* example.com is redirected, so we tell libcurl to follow redirection */
                    easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, 1L);

                    Easy.SSLContextFunction sf = new Easy.SSLContextFunction(OnSSLContext);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);

                    easy.SetOpt(CURLoption.CURLOPT_URL, URL);

                    /* use a GET to fetch this */
                    //easy.SetOpt(CURLoption.CURLOPT_HTTPGET, 1L);

                    easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

                    //write cookie
                    easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, "cookies.txt");

                    easy.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }
            string s = Encoding.UTF8.GetString(dataRecorder.Written.ToArray());

            //Console.WriteLine(s);
            File.WriteAllText("libcurl-get.txt", s);
            Console.WriteLine("\r\n[END-GET]");
        }
Exemplo n.º 27
0
        public bool DownloadStaticURL(string url, string OutputFilename)
        {
            string path = Path.GetDirectoryName(OutputFilename);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            try
            {
                _fileStream = new FileStream(OutputFilename, FileMode.Create);

                //Todo: move Curl.GlobalInit out, just invoke once.
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

                Easy easy             = new Easy();
                Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);

                Easy.ProgressFunction pf = new Easy.ProgressFunction(ProgressFunction);

                easy.SetOpt(CURLoption.CURLOPT_NOPROGRESS, false);
                easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf);
                if (!string.IsNullOrEmpty(url))
                {
                    easy.SetOpt(CURLoption.CURLOPT_URL, url);
                }

                easy.Perform();
                easy.Cleanup();
                Curl.GlobalCleanup();

                _fileStream.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                _fileStream.Close();
                return(false);
            }

            return(true);
        }
Exemplo n.º 28
0
    public static void Main(String[] args)
    {
        Curl.GlobalInit(CurlInitFlag.All);

        try
        {
            using (var easy = new CurlEasy())
            {
                easy.Url           = "http://www.google.com/";
                easy.WriteFunction = OnWriteData;
                easy.Perform();
            }
        }
        finally
        {
            Curl.GlobalCleanup();
        }
    }
Exemplo n.º 29
0
        public void Status(string userName, string password, string mdOrder)
        {
            if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password) || String.IsNullOrEmpty(mdOrder))
            {
            }
            else
            {
                connectLog = new StringBuilder();
                headerLog  = new StringBuilder();
                answer     = new StringBuilder();

                //string URL = String.Format("https://mpi-test.bgpb.by:9443/payment/rest/getOrderStatus.do?userName={0}&password={1}&mdOrder={2}", userName, password, mdOrder);
                string URL = String.Format("https://mpi-test.bgpb.by:9443/payment/rest/getOrderStatus.do?userName={0}&password={1}&orderId={2}&language=en", userName, password, mdOrder);

                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

                using (Easy easy = new Easy())
                {
                    easy.SetOpt(CURLoption.CURLOPT_URL, URL);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 1);
                    easy.SetOpt(CURLoption.CURLOPT_SSLCERT, "mpi-test.bgpb.by.crt");
                    easy.SetOpt(CURLoption.CURLOPT_SSLKEY, "mpi.test.key");
                    easy.SetOpt(CURLoption.CURLOPT_SSLKEYPASSWD, "Bgpb2019");
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, 1);
                    easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, "60");

                    Easy.DebugFunction df = new Easy.DebugFunction(OnDebug_Status);
                    easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
                    easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);

                    easy.SetOpt(CURLoption.CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko");
                    easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, 1);
                    easy.SetOpt(CURLoption.CURLOPT_HTTPGET, true);
                    easy.Perform();
                }

                connectLogText = connectLog.ToString(); connectLog = null;
                headerLogText  = headerLog.ToString(); headerLog = null;
                answerText     = answer.ToString(); answer = null;
                Curl.GlobalCleanup();
            }
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            try
            {
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

                Easy easy             = new Easy();
                Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);

                if (args.Length > 1)
                {
                    easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
                }
                else
                {
                    string url = string.Empty;
                    Console.WriteLine("Download URL: ");
                    url = "http://jashliao.pixnet.net/blog";//Console.ReadLine();

                    easy.SetOpt(CURLoption.CURLOPT_URL, url);
                }
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, 1);
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                easy.SetOpt(CURLoption.CURLOPT_NOPROGRESS, 1);

                string path = string.Empty;
                Console.WriteLine("Save Path: ");
                path       = "123.html";//Console.ReadLine();
                Program.bw = new BinaryWriter(new FileStream(path, FileMode.Create));

                easy.Perform();

                easy.Cleanup();

                Program.bw.Close();

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }