GetInfo() public method

Extract DateTime information from an Easy object.
This is thrown if /// the native CURL* handle wasn't created successfully.
public GetInfo ( CURLINFO info, System.DateTime &dt ) : CURLcode
info CURLINFO One of the values in the /// enumeration. In this case, it must /// specifically be . ///
dt System.DateTime Reference to a DateTime value.
return CURLcode
Example #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;
        }
Example #2
0
        public bool DownloadFile(string httpPath, string savePath)
        {
            try
            {
                if (_isloggedIn)
                {
                    easy.SetOpt(LibCurl.CURLoption.CURLOPT_WRITEFUNCTION, wf);

                    fileDownload = new FileStream(savePath, FileMode.Create);
                    ///replace space with %20
                    string a = " ";
                    string b = "&20";
                    httpPath = httpPath.Replace(a, b);

                    easy.SetOpt(LibCurl.CURLoption.CURLOPT_URL, httpPath);
                    LibCurl.CURLcode exec = easy.Perform();
                    //CURLcode exec = DrupCurlPerform();

                    double d = 0;
                    easy.GetInfo(LibCurl.CURLINFO.CURLINFO_CONTENT_LENGTH_DOWNLOAD, ref d);
                    //easy.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION,null);
                    fileDownload.Close();
                    if ((d == 0) || (this.HttpConnectCode != 200) || (!DrutNETBase.FileExists(savePath)))
                    {
                        sendLogEvent("Can't download file with Curl: " + exec.ToString() + "\n", "Curl", Enums.MessageType.Error);
                        return(false);
                    }

                    return(true);
                }
                else
                {
                    sendLogEvent("CURL not logged-in", "Curl" + "\n", Enums.MessageType.Error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errorMessage(ex.Message);
                return(false);
            }
        }
Example #3
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);
        }
Example #4
0
    public static void Main(String[] args)
    {
        try {
            Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);

            Easy easy = new Easy();
            easy.SetOpt(CURLoption.CURLOPT_URL, args[0]);
            easy.SetOpt(CURLoption.CURLOPT_PRIVATE, "Private string");
            easy.SetOpt(CURLoption.CURLOPT_FILETIME, true);
            easy.Perform();

            // now, exercise the various GetInfo stuff
            double d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_CONNECT_TIME, ref d);
            Console.WriteLine("Connect Time: {0}", d);

            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_CONTENT_LENGTH_DOWNLOAD, ref d);
            Console.WriteLine("Content Length (Download): {0}", d);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_CONTENT_LENGTH_UPLOAD, ref d);
            Console.WriteLine("Content Length (Upload): {0}", d);
    
            string s = null;
            easy.GetInfo(CURLINFO.CURLINFO_CONTENT_TYPE, ref s);
            Console.WriteLine("Content Type: {0}", s);
    
            DateTime dt = new DateTime(0);
            easy.GetInfo(CURLINFO.CURLINFO_FILETIME, ref dt);
            Console.WriteLine("File time: {0}", dt);
    
            int n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_HEADER_SIZE, ref n);
            Console.WriteLine("Header Size: {0}", n);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_HTTPAUTH_AVAIL, ref n);
            Console.WriteLine("Authentication Bitmask: {0}", n);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_HTTP_CONNECTCODE, ref n);
            Console.WriteLine("HTTP Connect Code: {0}", n);
    
            d = 0.0;            
            easy.GetInfo(CURLINFO.CURLINFO_NAMELOOKUP_TIME, ref d);
            Console.WriteLine("Name Lookup Time: {0}", d);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_OS_ERRNO, ref n);
            Console.WriteLine("OS Errno: {0}", n);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_PRETRANSFER_TIME, ref d);
            Console.WriteLine("Pretransfer time: {0}", d);
    
            object o = null;
            easy.GetInfo(CURLINFO.CURLINFO_PRIVATE, ref o);
            Console.WriteLine("Private Data: {0}", o);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_PROXYAUTH_AVAIL, ref n);
            Console.WriteLine("Proxy Authentication Schemes: {0}", n);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_REDIRECT_COUNT, ref n);
            Console.WriteLine("Redirect count: {0}", n);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_REDIRECT_TIME, ref d);
            Console.WriteLine("Redirect time: {0}", d);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_REQUEST_SIZE, ref n);
            Console.WriteLine("Request size: {0}", n);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_RESPONSE_CODE, ref n);
            Console.WriteLine("Response code: {0}", n);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_SIZE_DOWNLOAD, ref d);
            Console.WriteLine("Download size: {0}", d);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_SIZE_UPLOAD, ref d);
            Console.WriteLine("Upload size: {0}", d);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_SPEED_DOWNLOAD, ref d);
            Console.WriteLine("Download speed: {0}", d);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_SPEED_UPLOAD, ref d);
            Console.WriteLine("Upload speed: {0}", d);
    
            n = 0;
            easy.GetInfo(CURLINFO.CURLINFO_SSL_VERIFYRESULT, ref n);
            Console.WriteLine("SSL verification result: {0}", n);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_STARTTRANSFER_TIME, ref d);
            Console.WriteLine("Start transfer time: {0}", d);
    
            d = 0.0;
            easy.GetInfo(CURLINFO.CURLINFO_TOTAL_TIME, ref d);
            Console.WriteLine("Total time: {0}", d);
    
            easy.Cleanup();
            Curl.GlobalCleanup();
        }
        catch(Exception ex) {
            Console.WriteLine(ex);
        }
    }