/// <summary> /// Creates a CurlEasy object that calls the given writeback function /// when data is received. /// Can also write back the header. /// </summary> /// <returns>The CurlEasy object</returns> /// /// Adapted from MultiDemo.cs in the curlsharp repo public static CurlEasy CreateEasy(string url, CurlWriteCallback wf, CurlHeaderCallback hwf = null) { if (!_initComplete) { Log.Warn("Curl environment not pre-initialised, performing non-threadsafe init."); Init(); } var easy = new CurlEasy(); easy.Url = url; easy.WriteData = null; easy.WriteFunction = wf; if (hwf != null) { easy.HeaderFunction = hwf; } easy.Encoding = "deflate, gzip"; easy.FollowLocation = true; // Follow redirects easy.UserAgent = Net.UserAgentString; easy.SslVerifyPeer = true; var caBundle = ResolveCurlCaBundle(); if (caBundle != null) { easy.CaInfo = caBundle; } return(easy); }
/// <summary> /// Creates a CurlEasy object that writes to the given stream. /// Can call a writeback function for the header. /// </summary> public static CurlEasy CreateEasy(string url, FileStream stream, CurlHeaderCallback hwf = null) { // Let's make a happy closure around this stream! return(CreateEasy(url, delegate(byte[] buf, int size, int nmemb, object extraData) { stream.Write(buf, 0, size * nmemb); return size * nmemb; }, hwf)); }
/// <summary> /// Creates a CurlEasy object that calls the given writeback function /// when data is received. /// Can also write back the header. /// </summary> /// <returns>The CurlEasy object</returns> /// /// Adapted from MultiDemo.cs in the curlsharp repo public static CurlEasy CreateEasy(string url, string authToken, CurlWriteCallback wf, CurlHeaderCallback hwf = null) { if (!_initComplete) { Log.Warn("Curl environment not pre-initialised, performing non-threadsafe init."); Init(); } var easy = new CurlEasy() { Url = url, WriteData = null, WriteFunction = wf, Encoding = "deflate, gzip", // Follow redirects FollowLocation = true, UserAgent = Net.UserAgentString, SslVerifyPeer = true, HeaderData = null, HttpHeader = GetHeaders(authToken), }; if (hwf != null) { easy.HeaderFunction = hwf; } var caBundle = ResolveCurlCaBundle(); if (caBundle != null) { easy.CaInfo = caBundle; } return(easy); }