Esempio n. 1
1
        public static bool gopost(string url, string user, string password,  string data, TradeLink.API.DebugDelegate deb, out string result)
        {
            debs = deb;
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();
            rresult = new StringBuilder();
            hasresult = false;

            Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

            // simple post - with a string
            easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,
                data);
            Slist sl = new Slist();
            sl.Append("Content-Type:application/xml");
            sl.Append("Accept: application/xml");
            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                "Mozilla 4.0 (compatible; MSIE 6.0; Win32");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password);
            CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC;
            easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag);
            easy.SetOpt(CURLoption.CURLOPT_URL,url);
            
            easy.SetOpt(CURLoption.CURLOPT_POST, true);
            if (debs!=null)
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
            


            CURLcode err = easy.Perform();
            int waits = 0;
            int maxwaits = 200;
            while (!hasresult && (waits++<maxwaits))
                System.Threading.Thread.Sleep(10);

            int rcodei = 0;
            CURLcode rcode = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei);


            if (!hasresult && (deb != null))
                deb(easy.StrError(err));

            easy.Cleanup();



            Curl.GlobalCleanup();
            result = rresult.ToString();



            return hasresult;
        }
Esempio n. 2
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);
        }
    }
Esempio n. 3
0
        public static void PerformPostMultipartRequest(string query, string postData)
        {
            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,
                postData);

            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                "C# EchoNest Lib");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_URL,
                query);
            easy.SetOpt(CURLoption.CURLOPT_POST, true);

            CURLcode res = easy.Perform();

            if (res != CURLcode.CURLE_OK)
                throw new WebException("Post operation failed");

            easy.Cleanup();

            Curl.GlobalCleanup();
        }
Esempio 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);

            // 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);
        }
    }
Esempio n. 5
0
 public FastRequest(string url)
 {
     Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
     easy.SetOpt(CURLoption.CURLOPT_URL, url);
     easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
     easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
 }
Esempio n. 6
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);
        }
    }
Esempio n. 7
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);
        }
    }
Esempio 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, args[0]);
            easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");

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

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

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

            Easy easy1 = new Easy();
            String s1 = (String)args[0].Clone();
            easy1.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy1.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy1.SetOpt(CURLoption.CURLOPT_WRITEDATA, s1);

            Easy easy2 = new Easy();
            String s2 = (String)args[1].Clone();
            easy2.SetOpt(CURLoption.CURLOPT_URL, args[1]);
            easy2.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy2.SetOpt(CURLoption.CURLOPT_WRITEDATA, s2);

            Multi multi = new Multi();
            multi.AddHandle(easy1);
            multi.AddHandle(easy2);

            int stillRunning = 1;
            // call Multi.Perform right away (note ref qualifier)
            while (multi.Perform(ref stillRunning) ==
                CURLMcode.CURLM_CALL_MULTI_PERFORM);

            while (stillRunning != 0)
            {
                multi.FDSet();
                int rc = multi.Select(1000); // one second
                switch(rc)
                {
                    case -1:
                        Console.WriteLine("Multi.Select() returned -1");
                        stillRunning = 0;
                        break;

                    case 0:
                    default:
                    {
                        while (multi.Perform(ref stillRunning) ==
                            CURLMcode.CURLM_CALL_MULTI_PERFORM);
                        break;
                    }
                }
            }

            // various cleanups
            multi.Cleanup();
            easy1.Cleanup();
            easy2.Cleanup();
            Curl.GlobalCleanup();
        }
        catch(Exception ex) {
            Console.WriteLine(ex);
        }
    }
Esempio n. 10
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();
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
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);
        }
    }
Esempio n. 17
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());
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        public CURLBrowser(string proxy)
        {
            easy = new Easy();
            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);

            Random rnd = new Random();

            UserAgent = Common.useragents[rnd.Next(0, Common.useragents.Count)];

            easy.SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, "");
            if (proxy != "")
            {
                string[] proxyDetails = proxy.Split(',');
                easy.SetOpt(CURLoption.CURLOPT_PROXY, proxyDetails[0]);
                easy.SetOpt(CURLoption.CURLOPT_PROXYUSERPWD, proxyDetails[1] + ":" + proxyDetails[2]);
            }

            doc   = new HtmlAgilityPack.HtmlDocument();
            Proxy = proxy;
        }
Esempio n. 20
0
        public static void PerformPostMultipartRequest(string query, string postData)
        {
            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,
                        postData);

            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                        "C# EchoNest Lib");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_URL,
                        query);
            easy.SetOpt(CURLoption.CURLOPT_POST, true);


            CURLcode res = easy.Perform();

            if (res != CURLcode.CURLE_OK)
            {
                throw new WebException("Post operation failed");
            }



            easy.Cleanup();



            Curl.GlobalCleanup();
        }
Esempio n. 21
0
        public static string get_raw_http(object p)
        {
            if (p == null)
            {
                p = "http://localhost/";
            }

            string        url = p.ToString();
            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) =>
                {
                    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();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(bi.ToString());
        }
Esempio n. 22
0
        private string steam()
        {
            string a = readSteamUser();
            if (a == MasterBot[0][0])
            {
                try
                {
                    string steamCommunityIDs = "";
                    for (int i = 0; i < steamUsers.Length; i++)
                    {
                        if (i == 0)
                            steamCommunityIDs = steamUsers[i];
                        else
                            steamCommunityIDs += "," + steamUsers[i];
                    }

                    string appkey = sbprop._SteamKey;
                    string waurl = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + appkey + "&steamids=" + steamCommunityIDs;
                    Easy.WriteFunction wf = new Easy.WriteFunction(steamOnWrite);
                    steamBuffer = "";
                    sendRequest(waurl, wf, "");
                    return parseSteamWrite();
                }
                catch (Exception e)
                {
                    return e.ToString();
                }
            }
            else
                return a;
        }
Esempio n. 23
0
 static public extern short curl_easy_setopt(IntPtr handle, int option, Easy.WriteFunction wf);
Esempio n. 24
0
        public static oResult test_https(Dictionary <string, object> request = null)
        {
            oResult rs = new oResult()
            {
                ok = false, request = request
            };

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

            if (string.IsNullOrWhiteSpace(url))
            {
                url = "https://vnexpress.net/ha-noi-de-xuat-keo-dai-cach-ly-xa-hoi-den-30-4-4084947.html";
            }

            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_WRITEFUNCTION, wf);

                Easy.SSLContextFunction sf = new Easy.SSLContextFunction((ctx, extraData) => CURLcode.CURLE_OK);
                easy.SetOpt(CURLoption.CURLOPT_SSL_CTX_FUNCTION, sf);

                easy.SetOpt(CURLoption.CURLOPT_URL, url);
                //easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");
                string file_crt = Path.Combine(_CONFIG.PATH_ROOT, @"bin\ca-bundle.crt");
                if (File.Exists(file_crt) == false)
                {
                    rs.error = "Cannot found file: " + file_crt;
                    return(rs);
                }
                easy.SetOpt(CURLoption.CURLOPT_CAINFO, file_crt);

                easy.Perform();
                easy.Dispose();

                Curl.GlobalCleanup();

                string s = bi.ToString();

                //string title = Regex.Match(s, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;

                s = new Regex(@"<script[^>]*>[\s\S]*?</script>").Replace(s, string.Empty);
                s = new Regex(@"<style[^>]*>[\s\S]*?</style>").Replace(s, string.Empty);
                s = new Regex(@"<noscript[^>]*>[\s\S]*?</noscript>").Replace(s, string.Empty);
                s = Regex.Replace(s, @"<meta(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<link(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<use(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<figure(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<!DOCTYPE(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<!--(.|\n)*?-->", string.Empty, RegexOptions.Singleline);

                s = Regex.Replace(s, @"(?:\r\n|\r(?!\n)|(?<!\r)\n){2,}", "\r\n");

                rs.data = s;
                rs.ok   = true;
                rs.type = DATA_TYPE.HTML_TEXT;
            }
            catch (Exception ex)
            {
                rs.error = "ERR: " + ex.Message;
            }

            return(rs);
        }
Esempio n. 25
0
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

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

            Easy   easy1 = new Easy();
            String s1    = (String)args[0].Clone();
            easy1.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy1.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy1.SetOpt(CURLoption.CURLOPT_WRITEDATA, s1);

            Easy   easy2 = new Easy();
            String s2    = (String)args[1].Clone();
            easy2.SetOpt(CURLoption.CURLOPT_URL, args[1]);
            easy2.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy2.SetOpt(CURLoption.CURLOPT_WRITEDATA, s2);

            Multi multi = new Multi();
            multi.AddHandle(easy1);
            multi.AddHandle(easy2);

            int stillRunning = 1;
            // call Multi.Perform right away (note ref qualifier)
            while (multi.Perform(ref stillRunning) ==
                   CURLMcode.CURLM_CALL_MULTI_PERFORM)
            {
                ;
            }

            while (stillRunning != 0)
            {
                multi.FDSet();
                int rc = multi.Select(1000); // one second
                switch (rc)
                {
                case -1:
                    Console.WriteLine("Multi.Select() returned -1");
                    stillRunning = 0;
                    break;

                case 0:
                default:
                {
                    while (multi.Perform(ref stillRunning) ==
                           CURLMcode.CURLM_CALL_MULTI_PERFORM)
                    {
                        ;
                    }
                    break;
                }
                }
            }

            // various cleanups
            multi.Cleanup();
            easy1.Cleanup();
            easy2.Cleanup();
            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
    public static string[] MultiPost(string[] Url, string post, int timeOut)
    {
        Result = new string[post.Length];
        try
        {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            //Easy.HeaderFunction hf = new Easy.HeaderFunction(OnHeaderData);
            Easy[] easy  = new Easy[Url.Length];
            Multi  multi = new Multi();
            for (int i = 0; i < Url.Length; i++)
            {
                if (Url[i] != null)
                {
                    easy[i] = new Easy();
                    easy[i].SetOpt(CURLoption.CURLOPT_URL, Url[i]);
                    easy[i].SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                    easy[i].SetOpt(CURLoption.CURLOPT_WRITEDATA, i);
                    //easy[i].SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, hf);
                    //easy[i].SetOpt(CURLoption.CURLOPT_HEADERDATA, i);
                    easy[i].SetOpt(CURLoption.CURLOPT_TIMEOUT, timeOut);
                    easy[i].SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
                    Slist sl = new Slist();
                    sl.Append(Header);
                    easy[i].SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
                    easy[i].SetOpt(CURLoption.CURLOPT_POSTFIELDS, post);
                    easy[i].SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
                    easy[i].SetOpt(CURLoption.CURLOPT_POST, true);
                    //easy[i].SetOpt(CURLoption.CURLOPT_NOBODY, true);
                    if (Url[i].Contains("https"))
                    {
                        easy[i].SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 1);
                        easy[i].SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
                    }
                    multi.AddHandle(easy[i]);
                }
            }
            int stillRunning = 1;
            while (multi.Perform(ref stillRunning) == CURLMcode.CURLM_CALL_MULTI_PERFORM)
            {
                ;
            }
            while (stillRunning != 0)
            {
                multi.FDSet();
                int rc = multi.Select(1000);     // one second
                switch (rc)
                {
                case -1:
                    stillRunning = 0;
                    break;

                case 0:
                default:
                {
                    while (multi.Perform(ref stillRunning) == CURLMcode.CURLM_CALL_MULTI_PERFORM)
                    {
                        ;
                    }
                    break;
                }
                }
            }
            // various cleanups
            multi.Cleanup();
            for (int i = 0; i < easy.Length; i++)
            {
                easy[i].Cleanup();
            }
            Curl.GlobalCleanup();
        }
        catch (Exception)
        {
            //r = ex+"";
        }
        return(Result);
    }
Esempio n. 27
0
        public string GetPostPage(string url, string postData, string proxyPort, string userPassword, bool deleteCookies = true)
        {
            lock (thisLock){
                if (deleteCookies)
                {
                    DeleteCookies();
                }

                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
                Easy easy = new Easy();
                try
                {
                    this.CurrentPage = string.Empty;
                    Easy.WriteFunction wf = this.WriteData;
                    easy.SetOpt(CURLoption.CURLOPT_URL, url);
                    easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYHOST, 0);
                    easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, 0);
                    if (!string.IsNullOrEmpty(proxyPort))
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXY, proxyPort);
                    }
                    if (!string.IsNullOrEmpty(userPassword))
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYUSERPWD, userPassword);
                    }
                    if (!string.IsNullOrEmpty(proxyPort))
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_SOCKS5);
                    }
                    easy.SetOpt(CURLoption.CURLOPT_USERAGENT, UserAgent);
                    easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, "injector.cookie");
                    easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, "injector.cookie");
                    easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, 1);
                    easy.SetOpt(CURLoption.CURLOPT_AUTOREFERER, 1);
                    easy.SetOpt(CURLoption.CURLOPT_CONNECTTIMEOUT, 15);
                    if (!string.IsNullOrEmpty(postData))
                    {
                        easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, postData);
                    }
                    easy.Perform();
                    return(this.CurrentPage);
                }
                catch (Exception exp) {
                    if (exp is ThreadAbortException)
                    {
                        this.CurrentPage = string.Empty;
                    }
                    Cache.Instance.Log("[GetPostPage] Exception " + exp.ToString());
                }
                finally
                {
                    if (easy != null)
                    {
                        easy.Cleanup();
                    }
                    Curl.GlobalCleanup();
                }
                return(this.CurrentPage = string.Empty);
            }
        }
Esempio n. 28
0
        public static bool gomultipartpost(string url, string user, string password, string fname, string fpath, int ticketid, int maxwaitsec, bool showprogress, TradeLink.API.DebugDelegate deb, out string result)
        {
            debs = deb;
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            rresult   = new StringBuilder();
            hasresult = false;

            MultiPartForm mf = new MultiPartForm();


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



            // <input type="File" name="f1">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[file]",
                          CURLformoption.CURLFORM_FILE, fpath,
                          CURLformoption.CURLFORM_CONTENTTYPE, "application/octet-stream",
                          CURLformoption.CURLFORM_END);

            // <input name="frmFileDate">
            if (ticketid != 0)
            {
                mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[ticket_id]",
                              CURLformoption.CURLFORM_COPYCONTENTS, ticketid.ToString(),
                              CURLformoption.CURLFORM_END);
            }

            if (showprogress)
            {
                Easy.ProgressFunction pf = new Easy.ProgressFunction(OnProgress);
                easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf);
            }


            Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf);
            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

            // simple post - with a string
            //easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,data);
            Slist sl = new Slist();

            //sl.Append("Content-Type:multipart/form-data");
            sl.Append("Accept: application/xml");
            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                        "Mozilla 4.0 (compatible; MSIE 6.0; Win32");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password);
            CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC;

            easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag);
            easy.SetOpt(CURLoption.CURLOPT_URL, url);

            //easy.SetOpt(CURLoption.CURLOPT_POST, true);
            if (debs != null)
            {
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
            }



            CURLcode err      = easy.Perform();
            int      waits    = 0;
            int      maxwaits = 100 * maxwaitsec;

            while (!hasresult && (waits++ < maxwaits))
            {
                System.Threading.Thread.Sleep(10);
            }

            int      rcodei = 0;
            CURLcode rcode  = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei);


            if (!hasresult && (deb != null))
            {
                deb(easy.StrError(err));
            }

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


            Curl.GlobalCleanup();
            result = rresult.ToString();



            return(hasresult && (rcodei == 201));
        }
Esempio n. 29
0
 // static class constructor to create static delegate
 static EasyThread()
 {
     Console.WriteLine("EasyThread class constructor");
     wf = new Easy.WriteFunction(OnWriteData);
 }
Esempio n. 30
0
        /// <summary>
        /// Universal method to load page
        /// </summary>
        /// <param name="url">url to load. It is ignored if form is not null.</param>
        /// <param name="form">form to submit. Should be null if url is not null.</param>
        /// <param name="send_cookies"></param>
        /// <returns></returns>
        CURLcode load_page(string url, bool send_cookies)
        {
            try
            {
                if (Cache.GetCachedFile(ref url, out WR.HtmlResult, out WR.ResponseUrl))
                {
                    WR.web_routine_status = WebRoutineStatus.CACHED;
                    WR.log.Write("From cache: " + url);
                    return(CURLcode.CURLE_OK);
                }

                if (UseCommonCookieFile)
                {
                    copy_common_cookie_file2thread_cookie_file();
                }

                result_ms.Position = 0;
                result_sb.Length   = 0;
                encode_type        = EncodeType.NONE;
                easy            = new Easy();
                content_length  = -1;
                WR.ErrorMessage = null;
                WR.HtmlResult   = null;
                //WR.saved_file = null;
                WR.log.Write("Downloading:" + url);
                if (WR.BTC != null)
                {
                    WR.BTC.BTS.ProgressMax   = 0;
                    WR.BTC.BTS.ProgressValue = 100;
                    WR.BTC.BTS.Status        = "Sleeping Crawl Interval: " + Config.Web.CrawlTimeIntervalInMss.ToString();
                    WR.BTC.DisplayStatus();
                    Thread.Sleep(Config.Web.CrawlTimeIntervalInMss);
                    WR.BTC.BTS.Status = "URL:" + url;
                    WR.BTC.DisplayStatus();
                }
                WR.web_routine_status = WebRoutineStatus.UNDEFINED;

                //if (flagReceiveDebugMessages)
                //{
                //    Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
                //    easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
                //    easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
                //}

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

                easy.SetOpt(CURLoption.CURLOPT_URL, url);

                if (url.StartsWith("https"))
                {
                    easy.SetOpt(CURLoption.CURLOPT_CAINFO, "ca-bundle.crt");
                }

                Easy.HeaderFunction hf = new Easy.HeaderFunction(OnHeaderData);
                easy.SetOpt(CURLoption.CURLOPT_HEADERFUNCTION, hf);

                Slist sl = new Slist();
                sl.Append("Accept: " + WR.HttpRequestAcceptHeader);
                sl.Append("Referer: " + WR.HttpRequestRefererHeader);
                sl.Append("Accept-Encoding: gzip, deflate");
                easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);

                easy.SetOpt(CURLoption.CURLOPT_USERAGENT, Config.Web.HttpUserAgent);

                easy.SetOpt(CURLoption.CURLOPT_COOKIEJAR, CookieFile);

                if (send_cookies)
                {
                    easy.SetOpt(CURLoption.CURLOPT_COOKIEFILE, CookieFile);
                }

                if (WR.MaxAutoRedirectionCount >= 0)
                {
                    easy.SetOpt(CURLoption.CURLOPT_MAXREDIRS, WR.MaxAutoRedirectionCount);
                }

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

                easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);

                if (proxy != null)
                {
                    easy.SetOpt(CURLoption.CURLOPT_PROXY, proxy.Ip);
                    easy.SetOpt(CURLoption.CURLOPT_PROXYPORT, proxy.Port);

                    easy.SetOpt(CURLoption.CURLOPT_PROXYAUTH, CURLhttpAuth.CURLAUTH_ANY);
                    if (proxy.Login != "" || proxy.Password != "")
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYUSERPWD, proxy.Login + ":" + proxy.Password);
                    }
                    if (proxy.Type == ProxyType.SOCKS5)
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_SOCKS5);
                    }
                    else if (proxy.Type == ProxyType.SOCKS4)
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_SOCKS4);
                    }
                    else
                    {
                        easy.SetOpt(CURLoption.CURLOPT_PROXYTYPE, CURLproxyType.CURLPROXY_HTTP);
                    }
                    easy.SetOpt(CURLoption.CURLOPT_PROXYAUTH, CURLhttpAuth.CURLAUTH_ANY);
                }
                if (WR.BTC != null)
                {
                    if (proxy != null)
                    {
                        WR.BTC.BTS.Proxy = proxy.Ip + ":" + proxy.Port;
                    }
                    else
                    {
                        WR.BTC.BTS.Proxy = "NOT USED";
                    }
                    WR.BTC.DisplayStatus();
                }

                easy.SetOpt(CURLoption.CURLOPT_TIMEOUT, Config.Web.HttpRequestTimeoutInSeconds);

                CURLcode rc = easy.Perform();

                easy.GetInfo(CURLINFO.CURLINFO_EFFECTIVE_URL, ref WR.ResponseUrl);

                easy.Cleanup();

                WR.HtmlResult = result_sb.ToString();

                if (rc != CURLcode.CURLE_OK)
                {
                    WR.ErrorMessage       = easy.StrError(rc);
                    WR.web_routine_status = WebRoutineStatus.DOWNLOAD_ERROR;
                    WR.log.Error("Download error: " + WR.ErrorMessage + "\nURL:" + url + "\nPROXY: " + proxy.Ip + ":" + proxy.Port);
                    return(rc);
                }

                if (UseCommonCookieFile)
                {
                    copy_thread_cookie_file2common_cookie_file();
                }

                if (WR.web_routine_status == WebRoutineStatus.UNDEFINED)
                {
                    WR.web_routine_status = WebRoutineStatus.OK;
                }

                WR.log.CacheDownloadedString(ref url, ref WR.ResponseUrl, ref WR.HtmlResult, WR.page_number++, WR.CycleIdentifier);

                return(rc);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception error)
            {
                WR.web_routine_status = WebRoutineStatus.EXCEPTION;
                WR.log.Error(error.Message + "\nURL: " + url + "\nPROXY: " + proxy.Ip + ":" + proxy.Port);

                if (easy != null)
                {
                    easy.Cleanup();
                }
            }

            return(CURLcode.CURLE_FAILED_INIT);
        }
Esempio n. 31
0
 private void wolfram(string arg)
 {
     string app_key = sbprop._sWolframKey;
     string format = "plaintext";
     string waurl = "http://api.wolframalpha.com/v2/query?input=" + arg + "&format=" +
         format + "&appid=" + app_key + "&async=true";
     Easy.WriteFunction wf = new Easy.WriteFunction(wolframOnWrite);
     sendRequest(waurl, wf, "");
 }
Esempio n. 32
0
        public static bool gomultipartpost(string url, string user, string password, string fname, string fpath, int ticketid,int maxwaitsec, bool showprogress, TradeLink.API.DebugDelegate deb, out string result)
        {
            debs = deb;
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();
            rresult = new StringBuilder();
            hasresult = false;

            MultiPartForm mf = new MultiPartForm();


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



            // <input type="File" name="f1">
            mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[file]",
                CURLformoption.CURLFORM_FILE, fpath,
                CURLformoption.CURLFORM_CONTENTTYPE, "application/octet-stream",
                CURLformoption.CURLFORM_END);

            // <input name="frmFileDate">
            if (ticketid != 0)
                mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "document[ticket_id]",
                    CURLformoption.CURLFORM_COPYCONTENTS, ticketid.ToString(),
                    CURLformoption.CURLFORM_END);

            if (showprogress)
            {
                Easy.ProgressFunction pf = new Easy.ProgressFunction(OnProgress);
                easy.SetOpt(CURLoption.CURLOPT_PROGRESSFUNCTION, pf);
            }


            Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf);
            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

            // simple post - with a string
            //easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,data);
            Slist sl = new Slist();
            //sl.Append("Content-Type:multipart/form-data");
            sl.Append("Accept: application/xml");
            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                "Mozilla 4.0 (compatible; MSIE 6.0; Win32");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password);
            CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC;
            easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag);
            easy.SetOpt(CURLoption.CURLOPT_URL, url);

            //easy.SetOpt(CURLoption.CURLOPT_POST, true);
            if (debs != null)
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);



            CURLcode err = easy.Perform();
            int waits = 0;
            int maxwaits = 100*maxwaitsec;
            while (!hasresult && (waits++ < maxwaits))
                System.Threading.Thread.Sleep(10);

            int rcodei = 0;
            CURLcode rcode = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei);


            if (!hasresult && (deb != null))
                deb(easy.StrError(err));

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


            Curl.GlobalCleanup();
            result = rresult.ToString();



            return hasresult && (rcodei==201);
        }
Esempio n. 33
0
        //static bool curl_inited = false;
        public static string get_raw_https(object p)
        {
            //if (p == null || string.IsNullOrWhiteSpace(p.ToString())) return string.Empty;

            if (p == null)
            {
                p = "https://vnexpress.net/ha-noi-de-xuat-keo-dai-cach-ly-xa-hoi-den-30-4-4084947.html";
            }

            string url = p.ToString();

            try
            {
                //if (curl_inited == false)
                //{
                Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
                //    curl_inited = true;
                //}

                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_WRITEFUNCTION, wf);

                Easy.SSLContextFunction sf = new Easy.SSLContextFunction((ctx, extraData) => CURLcode.CURLE_OK);
                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, @"D:\cache_redis\ckv_lib\bin\ca-bundle.crt");

                easy.Perform();
                easy.Dispose();

                //Curl.GlobalCleanup();

                string s = bi.ToString();

                //string title = Regex.Match(s, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;

                s = new Regex(@"<script[^>]*>[\s\S]*?</script>").Replace(s, string.Empty);
                s = new Regex(@"<style[^>]*>[\s\S]*?</style>").Replace(s, string.Empty);
                s = new Regex(@"<noscript[^>]*>[\s\S]*?</noscript>").Replace(s, string.Empty);
                s = Regex.Replace(s, @"<meta(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<link(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<use(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<figure(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<!DOCTYPE(.|\n)*?>", string.Empty, RegexOptions.Singleline);
                s = Regex.Replace(s, @"<!--(.|\n)*?-->", string.Empty, RegexOptions.Singleline);

                s = Regex.Replace(s, @"(?:\r\n|\r(?!\n)|(?<!\r)\n){2,}", "\r\n");

                return(s);
            }
            catch (Exception ex)
            {
                return("ERR: " + ex.Message);
            }
        }
Esempio n. 34
0
        public string Load(string uri, string method = "GET", string postData = "", List <string> headers = null)
        {
            sb.Clear();
            Easy easy = new Easy();

            Easy.WriteFunction wf = MyWriteFunction;
            easy.SetOpt(CURLoption.CURLOPT_URL, uri);
            easy.SetOpt(CURLoption.CURLOPT_HEADER, DisplayHeaders);
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, FollowRedirects);

            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);
            }

            if (method.Equals("POST"))
            {
                easy.SetOpt(CURLoption.CURLOPT_POST, true);
            }

            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();

            //Console.WriteLine(code);
            if (code == 302)
            {
                RedirectUrl = FindString(sb.ToString(), "Location:(.*?)\n");
                //Console.WriteLine(RedirectUrl);
            }


            string page = sb.ToString();

            page = page.Replace("\r\n", "");   // strip all new lines and tabs
            page = page.Replace("\r", "");     // strip all new lines and tabs
            page = page.Replace("\n", "");     // strip all new lines and tabs
            page = page.Replace("\t", "");     // strip all new lines and tabs

            page = Regex.Replace(page, @">\s+<", "><");

            return(page);
        }
Esempio n. 35
0
        public short activate_via_apple_servers()
        {
            IntPtr activation_info_node;
            string activation_info;
            string activation_info_pre;


            string ICCID        = lockdownd_get_string_value(lockdownd_handle, "IntegratedCircuitCardIdentity");
            string IMEI         = lockdownd_get_string_value(lockdownd_handle, "InternationalMobileEquipmentIdentity");
            string IMSI         = lockdownd_get_string_value(lockdownd_handle, "InternationalMobileSubscriberIdentity");
            string serialNumber = lockdownd_get_string_value(lockdownd_handle, "SerialNumber");

            External.lockdownd_get_value(lockdownd_handle, null, "ActivationInfo", out activation_info_node);

            int type = (int)External.plist_get_node_type(activation_info_node);

            if (activation_info_node == null || External.plist_get_node_type(activation_info_node) != External.plist_type.PLIST_DICT)
            {
                MessageBox.Show("Unable to get ActivationInfo from lockdownd");
                return(-1);
            }

            uint   activation_info_size = 0;
            IntPtr activation_info_data; //char*

            External.plist_to_xml(activation_info_node, out activation_info_data, out activation_info_size);
            External.plist_free(activation_info_node);

            string activation_info_data_s = Marshal.PtrToStringAnsi(activation_info_data);


            //string activation_info_start = strstr(activation_info_data_s, "<dict>");
            int index_start = activation_info_data_s.IndexOf("<dict>");
            int index_end   = activation_info_data_s.IndexOf("</dict>");

            activation_info_pre = activation_info_data_s.Remove(0, index_start);
            activation_info     = activation_info_pre.Replace(activation_info_data_s.Remove(0, index_end + 7), "");
            if (index_start == -1)
            {
                MessageBox.Show("Unable to locate beginning of ActivationData.");
                return(-1);
            }
            if (index_end == -1)
            {
                MessageBox.Show("Unable to locate end of ActivationData.");
                return(-1);
            }
            index_end            = index_end + 7;
            activation_info_size = Convert.ToUInt32(index_end - index_start);
            IntPtr activationInfo = Marshal.StringToHGlobalAnsi(activation_info);

            Curl.GlobalInit(1);
            Easy easy_handle = new Easy();
            //easy_handle.SetOpt(CURLoption.CURLOPT_POSTFIELDS, "machine=linux&InStoreActivation=false&IMEI="+ IMEI+ "&IMSI=" + IMSI + "&ICCID=" + ICCID + "&AppleSerialNumber=" + serialNumber + "&activation-info=" + activation_info);
            MultiPartForm mf = new MultiPartForm();

            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "machine", CURLformoption.CURLFORM_COPYCONTENTS, "win32", CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "InStoreActivation", CURLformoption.CURLFORM_COPYCONTENTS, "false", CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "IMEI", CURLformoption.CURLFORM_COPYCONTENTS, IMEI, CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "IMSI", CURLformoption.CURLFORM_COPYCONTENTS, IMSI, CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "ICCID", CURLformoption.CURLFORM_COPYCONTENTS, ICCID, CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "AppleSerialNumber", CURLformoption.CURLFORM_COPYCONTENTS, serialNumber, CURLformoption.CURLFORM_END });
            mf.AddSection(new object[] { CURLformoption.CURLFORM_COPYNAME, "activation-info", CURLformoption.CURLFORM_COPYCONTENTS, activation_info, CURLformoption.CURLFORM_END });


            IntPtr curl_slist = new IntPtr();

            curl_slist = curl.curl_slist_append(curl_slist, "X-Apple-Tz: -14400");
            curl_slist = curl.curl_slist_append(curl_slist, "X-Apple-Store-Front: 143441-1");

            easy_handle.SetOpt(CURLoption.CURLOPT_HTTPHEADER, curl_slist);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            giftWriter = new System.IO.StreamWriter(ms);
            Easy.WriteFunction wf = new Easy.WriteFunction(OnWriteData);
            easy_handle.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf);
            easy_handle.SetOpt(CURLoption.CURLOPT_USERAGENT, "iTunes/9.1 (Macintosh; U; Intel Mac OS X 10.5.6)");
            easy_handle.SetOpt(CURLoption.CURLOPT_URL, "https://albert.apple.com/WebObjects/ALUnbrick.woa/wa/deviceActivation");
            easy_handle.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy_handle.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            ret = (short)easy_handle.Perform();



            index_start = output.IndexOf("<plist");
            index_end   = output.IndexOf("</plist>");

            string ticket_data_pre = output.Remove(0, index_start);
            string ticket_data     = ticket_data_pre.Replace(output.Remove(0, index_end + 8), "");

            int    ticket_length = ticket_data.Length;
            IntPtr ticket_dict;

            External.plist_from_xml(ticket_data, ticket_length, out ticket_dict);

            IntPtr iphone_activation_node = External.plist_dict_get_item(ticket_dict, "iphone-activation");

            if (iphone_activation_node.ToInt32() == 0)
            {
                iphone_activation_node = External.plist_dict_get_item(ticket_dict, "device-activation");
                if (iphone_activation_node.ToInt32() == 0)
                {
                    MessageBox.Show("Unable to find activation node.");
                    return(-2);
                }
            }

            IntPtr activation_record = External.plist_dict_get_item(iphone_activation_node, "activation-record");

            if (activation_record.ToInt32() == 0)
            {
                MessageBox.Show("Unable to find activation record.");
                return(-2);
            }

            ret = External.lockdownd_activate(lockdownd_handle, activation_record);
            return(ret);
        }
Esempio n. 36
0
        public bool DoDownload(string url, string hostname, string destFileName, int timeout, long bufferSize, WRITE_DATA_DELEGATE onWriteData, Object extraData)
        {
            bool ret  = false;
            Easy easy = new Easy();

            Easy.SetCurrentEasy(easy);

            Slist headers = new Slist();

            Easy.WriteFunction wf       = new Easy.WriteFunction(onWriteData);
            CURLcode           curlCode = CURLcode.CURLE_OK;

            try
            {
                headers.Append(HobaText.Format("Host: {0}", hostname));
                easy.SetOpt(CURLoption.CURLOPT_URL, url);
                easy.SetOpt(CURLoption.CURLOPT_WRITEDATA, extraData);
                easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
                easy.SetOpt(CURLoption.CURLOPT_HEADER, 0L);
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, 0L);
                easy.SetOpt(CURLoption.CURLOPT_BUFFERSIZE, (long)bufferSize);
                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);

                if (StartPoint > 0)
                {
                    easy.SetOpt(CURLoption.CURLOPT_RESUME_FROM, StartPoint);
                }

                int error = 0;
                curlCode = easy.Perform();
                if (curlCode == CURLcode.CURLE_OK)
                {
                    CURLcode code = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref error);
                    if (code == CURLcode.CURLE_OK && error == 200)
                    {
                        ret = true;
                    }
                }
            }
            finally
            {
                headers.FreeAll();

                Easy.SetCurrentEasy(null);
                easy.Cleanup();
            }

            if (curlCode != CURLcode.CURLE_OK)
            {
                throw new WebException(String.Format(
                                           "Error downloading \"{0}\": {1}", url, curlCode));
            }

            return(ret);
        }
Esempio n. 37
0
 // static class constructor to create static delegate
 static EasyThread() {
     Console.WriteLine("EasyThread class constructor");
     wf = new Easy.WriteFunction(OnWriteData);
 }
Esempio n. 38
0
        public static string Send(string ip, string type, string cmd)
        {
            IPAddress ipaddress;
            //Console.WriteLine("Enter IP Address");
            //string ipaddress = Console.ReadLine();
            bool ValidateIP = IPAddress.TryParse(ip, out ipaddress);

            if (ValidateIP)
            {
                string Isps4 = "";

                Ping      myPing = new Ping();
                PingReply reply  = myPing.Send(ip, 1000);
                if (reply != null)
                {
                    Isps4 = reply.Status.ToString();
                }

                if (Isps4 == "TimedOut")
                {
                    out1 = "TimedOut";
                }

                if (Isps4 != "TimedOut")
                {
                    try
                    {
                        Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

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

                        // simple post - with a string
                        easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, cmd);//"{\"title_id\":\"CUSA09311\"}";

                        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://" + ip + ":12800" + "/api/" + type); //"http://192.168.1.15:12800/api/is_exists");

                        easy.SetOpt(CURLoption.CURLOPT_POST, true);

                        easy.Perform();
                        easy.Dispose();

                        Curl.GlobalCleanup();
                        return(out1);
                    }
                    catch (Exception ex)
                    {
                        return(out1);
                        //Console.WriteLine(ex);
                    }
                }
            }
            else
            {
                out1 = "BadIP";
            }
            return(out1);
        }
Esempio n. 39
0
        public static bool gopost(string url, string user, string password, string data, TradeLink.API.DebugDelegate deb, out string result)
        {
            debs = deb;
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();

            rresult   = new StringBuilder();
            hasresult = false;

            Easy.WriteFunction wf = new Easy.WriteFunction(OnWritePostData);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);

            // simple post - with a string
            easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS,
                        data);
            Slist sl = new Slist();

            sl.Append("Content-Type:application/xml");
            sl.Append("Accept: application/xml");
            easy.SetOpt(CURLoption.CURLOPT_HTTPHEADER, sl);
            easy.SetOpt(CURLoption.CURLOPT_SSL_VERIFYPEER, false);
            easy.SetOpt(CURLoption.CURLOPT_USERAGENT,
                        "Mozilla 4.0 (compatible; MSIE 6.0; Win32");
            easy.SetOpt(CURLoption.CURLOPT_FOLLOWLOCATION, true);
            easy.SetOpt(CURLoption.CURLOPT_USERPWD, user + ":" + password);
            CURLhttpAuth authflag = CURLhttpAuth.CURLAUTH_BASIC;

            easy.SetOpt(CURLoption.CURLOPT_HTTPAUTH, authflag);
            easy.SetOpt(CURLoption.CURLOPT_URL, url);

            easy.SetOpt(CURLoption.CURLOPT_POST, true);
            if (debs != null)
            {
                easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
            }



            CURLcode err      = easy.Perform();
            int      waits    = 0;
            int      maxwaits = 200;

            while (!hasresult && (waits++ < maxwaits))
            {
                System.Threading.Thread.Sleep(10);
            }

            int      rcodei = 0;
            CURLcode rcode  = easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref rcodei);


            if (!hasresult && (deb != null))
            {
                deb(easy.StrError(err));
            }

            easy.Cleanup();



            Curl.GlobalCleanup();
            result = rresult.ToString();



            return(hasresult);
        }