Пример #1
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);
    }