コード例 #1
0
        public string HttpGet(string url, bool xml = false)
        {
            url = url.Replace(" ", "%20");
            //  url = SeasideResearch.LibCurlNet.Curl.Escape(url, url.Length);
            page = "";
            easy.SetOpt(CURLoption.CURLOPT_URL, url);
            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, null);

            if (xml)
            {
                Slist headers = new Slist();
                headers.Append("Accept: application/json, text/javascript, */*");
                headers.Append("X_REQUESTED_WITH: XMLHttpRequest");
                easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, headers);
            }

            easy.SetOpt(CURLoption.CURLOPT_HTTPGET, true);
            //easy.SetOpt(CURLoption.CURLOPT_REFERER, CurrentURL);
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);

            easy.Perform();

            easy.GetInfo(CURLINFO.CURLINFO_EFFECTIVE_URL, ref currentURL);

            if (this.page.Contains("<!DOCTYPE"))
            {
                doc.LoadHtml(this.page);
            }

            return(this.page);
        }
コード例 #2
0
ファイル: Html.cs プロジェクト: git-thinh/ben
        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);
        }
コード例 #3
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);
        }
    }
コード例 #4
0
        public string Perform()
        {
            CURLcode data = easy.Perform();

            easy.Dispose();
            return(buffer);
        }
コード例 #5
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);
        }
    }
コード例 #6
0
ファイル: Program.cs プロジェクト: git-thinh/tt2
    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);
        }
    }
コード例 #7
0
ファイル: FileUpload.cs プロジェクト: git-thinh/tt2
    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);
        }
    }
コード例 #8
0
    public void ThreadFunc()
    {
        Easy easy = new Easy();

        easy.SetOpt(CURLoption.CURLOPT_URL, url);
        easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
        easy.SetOpt(CURLoption.CURLOPT_WRITEDATA, url);
        easy.SetOpt(CURLoption.CURLOPT_SHARE, share);
        easy.Perform();
        //easy.Cleanup();
    }
コード例 #9
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]");
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        private static void Main(string[] args)
        {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            Easy.WriteFunction wf = MyWriteFunction;
            easy.SetOpt(CURLoption.CURLOPT_URL, "http://google.com/index.html");
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.Perform();
            easy.Cleanup();
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
コード例 #12
0
    public static Int64 GetUrlFileSizeEx(string url, string hostname, int timeout)
    {
        long size = -1;

        Easy easy = new Easy();

        Easy.SetCurrentEasy(easy);
        Slist headers = new Slist();

        headers.Append(HobaText.Format("Host: {0}", hostname));

        easy.SetOpt(CURLoption.CURLOPT_URL, url);
        easy.SetOpt(CURLoption.CURLOPT_HEADER, 1L);
        easy.SetOpt(CURLoption.CURLOPT_NOBODY, 1L);
        easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, headers);
        //easy.SetOpt(CURLoption.CURLOPT_IPRESOLVE, (long)CURLipResolve.CURL_IPRESOLVE_V4);
        easy.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, timeout / 1000);

        easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0L);
        easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 0L);

        int    error = 0;
        double downloadFileLength = 0.0f;

        if (easy.Perform() == CURLcode.CURLE_OK)
        {
            CURLcode code = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref error);

            if (code == CURLcode.CURLE_OK && error == 200)
            {
                easy.GetInfo(CURLINFO.CURLINFO_CONTENT_LENGTH_DOWNLOAD, ref downloadFileLength);
            }

            if (downloadFileLength >= 0.0f)
            {
                size = (int)downloadFileLength;
            }
        }
        else
        {
            size = -1;
        }

        headers.FreeAll();
        Easy.SetCurrentEasy(null);
        easy.Cleanup();

        return(size);
    }
コード例 #13
0
        public string HTTPPost(string URL, string http_headers, string Content)
        {
            easy     = new Easy();
            SockBuff = "";
            String proxy;

            try
            {
                Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);

                easy.SetOpt(CURLoption.CURLOPT_URL, URL);
                easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, "60");
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                easy.SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
                easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, CookieFile);
                easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, CookieFile);
                easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, http_headers);
                easy.SetOpt(CURLoption.CURLOPT_REFERER, referer);
                //easy.SetOpt(CURLoption.CURLOPT_POSTFIELDSIZE, Content.Length);
                easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
                easy.SetOpt(CURLoption.CURLOPT_STDERR, "test.txt");

                easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, 1);

                easy.SetOpt(CURLoption.CURLOPT_POST, true);
                easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, Content);


                if (URL.Contains("https"))
                {
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 1);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
                }

                if (Proxy != "")
                {
                    easy.SetOpt(CURLoption.CURLOPT_PROXY, Proxy);
                    easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_HTTP);
                }

                easy.Perform();
                easy.Cleanup();
            }
            catch
            {
            }
            return(SockBuff);
        }
コード例 #14
0
ファイル: clsCURL.cs プロジェクト: git-thinh/test
        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);
        }
コード例 #15
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);
        }
    }
コード例 #16
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]");
        }
コード例 #17
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);
        }
コード例 #18
0
        public MemoryStream LoadBinary(string uri, string method = "GET", string postData = "", List <string> headers = null)
        {
            ms = new MemoryStream();
            Easy easy = new Easy();

            Easy.WriteFunction wf = MyWriteBinaryFunction;
            easy.SetOpt(CURLoption.CURLOPT_URL, uri);
            easy.SetOpt(CURLoption.CURLOPT_HEADER, false);
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);

            Slist headerSlist = new Slist();

            if (headers != null)
            {
                foreach (var header in headers)
                {
                    headerSlist.Append(header);
                }
            }

            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, headerSlist);

            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, false);
            easy.SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
            easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, 10);
            easy.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, 3);

            if (!string.IsNullOrEmpty(postData))
            {
                easy.SetOpt(CURLoption.CURLOPT_POST, true);
                easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, postData);
            }

            easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, CookieFile);
            easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, CookieFile);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.Perform();
            int code = 0;

            easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref code);
            easy.Cleanup();

            return(ms);
        }
コード例 #19
0
ファイル: Headers.cs プロジェクト: jash-git/CS-libcurl
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();
            Easy.HeaderFunction hf = new Easy.HeaderFunction(OnHeaderData);

            easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy.SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, hf);
            easy.Perform();
            easy.Cleanup();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
コード例 #20
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();
            }
        }
コード例 #21
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);
            }
        }
コード例 #22
0
    public static void run()
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

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

            easy.SetOpt(CURLoption.CURLOPT_URL, "https://stackoverflow.com");
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.Perform();
            //easy.Cleanup();

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
コード例 #23
0
        public void Register(string orderNumber, string description, int amount, string userName, string password, string returnUrl, string failUrl, string sslCertPath, string sslKeyPath, string sslKeyPass)
        {
            if (amount == 0 || String.IsNullOrEmpty(orderNumber) || String.IsNullOrEmpty(returnUrl) || String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password))
            {
            }
            else
            {
                connectLog = new StringBuilder();
                headerLog  = new StringBuilder();
                answer     = new StringBuilder();

                //string URL = String.Format("https://mpi-test.bgpb.by:9443/payment/rest/register.do?amount={0}&currency=933&language=en&orderNumber={1}&returnUrl={2}&userName={3}&password={4}&failUrl={5}&description={6}", amount.ToString("N2").Replace(",", ""), orderNumber, returnUrl, userName, password, failUrl, description);
                string URL = String.Format("https://mpi-test.bgpb.by:9443/payment/rest/register.do?amount={0}&currency=933&language=en&orderNumber={1}&returnUrl={2}&userName={3}&password={4}&failUrl={5}&description={6}", amount, orderNumber, returnUrl, userName, password, failUrl, description);
                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, sslCertPath);     // HostingEnvironment.ApplicationPhysicalPath + "\\mpi-test.bgpb.by.crt");
                    easy.SetOpt(CURLoption.CURLOPT_SSLKEY, sslKeyPath);       //HostingEnvironment.ApplicationPhysicalPath + "\\mpi.test.key");
                    easy.SetOpt(CURLoption.CURLOPT_SSLKEYPASSWD, sslKeyPass); //"Bgpb2019");
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, 1);
                    easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, "60");

                    Easy.DebugFunction df = new Easy.DebugFunction(OnDebug_Register);
                    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_POST, true);
                    easy.Perform();
                }

                connectLogText = connectLog.ToString(); connectLog = null;
                headerLogText  = headerLog.ToString(); headerLog = null;
                answerText     = answer.ToString(); answer = null;
                Curl.GlobalCleanup();
            }
        }
コード例 #24
0
        public static string getString(string url)
        {
            StringBuilder bi = new StringBuilder();

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

                Easy easy = new Easy();

                Easy.WriteFunction wf = new Easy.WriteFunction((buf, size, nmemb, extraData) =>
                {
                    bi.Append(System.Text.Encoding.UTF8.GetString(buf));
                    return(size * nmemb);
                });
                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, url);
                easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

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

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex);
                bi.Append(url);
                bi.Append(Environment.NewLine);
                bi.Append(ex.Message);
                bi.Append(Environment.NewLine);
                bi.Append(ex.StackTrace);
            }
            return(bi.ToString());
        }
コード例 #25
0
ファイル: Html.cs プロジェクト: git-thinh/ben
        public static string f_http_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.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }

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

            return(s);
        }
コード例 #26
0
        public string HTTPGet(string URL, string Proxy)
        {
            easy     = new Easy();
            SockBuff = "";

            try
            {
                Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);

                easy.SetOpt(CURLoption.CURLOPT_URL, URL);
                easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, "60");
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                easy.SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
                easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, CookieFile);
                easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, CookieFile);
                easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);

                if (URL.Contains("https"))
                {
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 1);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
                }

                if (Proxy != "")
                {
                    easy.SetOpt(CURLoption.CURLOPT_PROXY, Proxy);
                    easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_HTTP);
                }

                easy.Perform();
                easy.Cleanup();
            }
            catch
            {
                Console.WriteLine("Get Request Error");
            }

            return(SockBuff);
        }
コード例 #27
0
        public void Perform_WhenWriteFunctionIsSet_RetrievesExpectedBytes()
        {
            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.SetOpt(CURLoption.CURLOPT_URL, "http://httpbin.org/bytes/16?seed=12345");
                    easy.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }

            byte[] expectedBytes = { 0x6A, 0x02, 0xD3, 0x4C, 0x5E, 0x31, 0x90, 0x29, 0x1F, 0x6E, 0x8F, 0x2C, 0x8D, 0x5A, 0xF5, 0x17 };
            Assert.That(dataRecorder.Written, Is.EqualTo(expectedBytes));
        }
コード例 #28
0
        public void Perform_WhenHeaderFunctionIsSet_RetrievesStringContainingContentType()
        {
            var dataRecorder = new EasyDataRecorder();

            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_DEFAULT);
            try
            {
                using (Easy easy = new Easy())
                {
                    easy.SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, (Easy.HeaderFunction)dataRecorder.HandleHeader);
                    easy.SetOpt(CURLoption.CURLOPT_HEADER, true);
                    easy.SetOpt(CURLoption.CURLOPT_URL, "http://httpbin.org/get");
                    easy.Perform();
                }
            }
            finally
            {
                Curl.GlobalCleanup();
            }

            Assert.That(dataRecorder.HeaderAsString, Does.Contain("Content-Type: application/json\r\n"));
        }
コード例 #29
0
    public static string GetUrlContentType(string url, string hostname, int timeout)
    {
        Easy easy = new Easy();

        Easy.SetCurrentEasy(easy);
        Slist headers = new Slist();

        headers.Append(HobaText.Format("Host: {0}", hostname));

        easy.SetOpt(CURLoption.CURLOPT_URL, url);
        easy.SetOpt(CURLoption.CURLOPT_HEADER, 1L);
        easy.SetOpt(CURLoption.CURLOPT_NOBODY, 1L);
        easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, headers);
        //easy.SetOpt(CURLoption.CURLOPT_IPRESOLVE, (long)CURLipResolve.CURL_IPRESOLVE_V4);
        easy.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, timeout / 1000);

        easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0L);
        easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 0L);

        int    error       = 0;
        string contentType = "";

        if (easy.Perform() == CURLcode.CURLE_OK)
        {
            CURLcode code = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref error);

            if (code == CURLcode.CURLE_OK && error == 200)
            {
                easy.GetInfo(CURLINFO.CURLINFO_CONTENT_TYPE, ref contentType);
            }
        }

        headers.FreeAll();
        Easy.SetCurrentEasy(null);
        easy.Cleanup();

        return(contentType);
    }
コード例 #30
0
ファイル: Upload.cs プロジェクト: jash-git/CS-libcurl
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            FileStream fs = new FileStream(args[0], FileMode.Open,
                                           FileAccess.Read, FileShare.Read);

            Easy easy = new Easy();

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

            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[1]);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD,
                        args[2] + ":" + args[3]);
            easy.SetOpt(CURLoption.CURLOPT_UPLOAD, true);
            easy.SetOpt(CURLoption.CURLOPT_INFILESIZE, fs.Length);

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

            fs.Close();

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