Ejemplo 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;
        }
Ejemplo n.º 2
0
    public static void Main(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);
        }
    }
Ejemplo n.º 3
0
    public static void run(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

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

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

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

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

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

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

            Easy easy = new Easy();

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

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

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

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

            Curl.GlobalCleanup();
        }
        catch (Exception ex) {
            Console.WriteLine(ex);
        }
    }
        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();
            }
        }
Ejemplo n.º 5
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);
        }
    }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
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();
            }
        }
Ejemplo n.º 8
0
    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);
        }
    }
Ejemplo n.º 9
0
    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);
        }
    }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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));
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        public void postFile(string imgpath, string bigimgpath)
        {
            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, "filecode",
                              CURLformoption.CURLFORM_COPYCONTENTS, this.fcode,
                              CURLformoption.CURLFORM_END);

                // <input type="File" name="f1">
                mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "file",
                              CURLformoption.CURLFORM_FILE, this.file_out,
                              CURLformoption.CURLFORM_CONTENTTYPE, "application/binary",
                              CURLformoption.CURLFORM_END);
                mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "img",
                              CURLformoption.CURLFORM_FILE, imgpath,
                              CURLformoption.CURLFORM_CONTENTTYPE, "application/binary",
                              CURLformoption.CURLFORM_END);

                mf.AddSection(CURLformoption.CURLFORM_COPYNAME, "bigimg",
                              CURLformoption.CURLFORM_FILE, bigimgpath,
                              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, this.weburl);
                easy.SetOpt(CURLoption.CURLOPT_HTTPPOST, mf);

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

                Curl.GlobalCleanup();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                FileStream   fs1 = new FileStream("D:\\test\\1.txt", FileMode.OpenOrCreate);
                StreamWriter sw1 = new StreamWriter(fs1);
                sw1.Write(ex.ToString());
                sw1.Close();
                fs1.Close();
            }

            FileStream   fs = new FileStream("D:\\test\\A.txt", FileMode.OpenOrCreate);
            StreamWriter sw = new StreamWriter(fs);

            sw.Write("aaaa ");
            sw.Close();
            fs.Close();
        }
Ejemplo n.º 14
0
        //currently used in: wolfram, steam
        private void sendRequest(string waurl, Easy.WriteFunction wf, string upload)
        {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
            Easy easy = new Easy();

            Easy.DebugFunction df = new Easy.DebugFunction(OnDebug);
            easy.SetOpt(CURLoption.CURLOPT_DEBUGFUNCTION, df);
            //easy.SetOpt(CURLoption.CURLOPT_VERBOSE, true);
            easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
            easy.SetOpt(CURLoption.CURLOPT_URL, waurl);
            if(upload != "")
                easy.SetOpt(CURLoption.CURLOPT_POSTFIELDS, upload);

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