Example #1
0
        internal static CurlCode EasyGetInfo(this CurlHandle handle, CurlInfo info, out string value)
        {
            CurlCode result = EasyGetInfo(handle, info, out IntPtr text);

            value = MarshalString.NativeToString(text);
            return(result);
        }
Example #2
0
        internal string GetError(CurlCode code)
        {
            if (code == CurlCode.NotInitialized)
            {
                return("Curl Global not initialized");
            }

            string error = MarshalString.Utf8ToString(_errorBuffer);

            return(string.IsNullOrEmpty(error) ? MarshalString.Utf8ToString(CurlNative.EasyStrError(code)) : error);
        }
Example #3
0
        public ArraySegment <byte> GetBytes(string url)
        {
            IntPtr urlpointer       = IntPtr.Zero;
            IntPtr useragentpointer = IntPtr.Zero;

            try
            {
                urlpointer = MarshalString.StringToUtf8(url);
                CurlCode result = CurlNative.EasySetOpt(_curl, CurlOption.Url, urlpointer);
                if (result != CurlCode.Ok)
                {
                    throw new CurlException(result, this);
                }

                useragentpointer = MarshalString.StringToUtf8(UserAgent);
                CurlCode result1 = CurlNative.EasySetOpt(_curl, CurlOption.Useragent, useragentpointer);
                if (result1 != CurlCode.Ok)
                {
                    throw new CurlException(result1, this);
                }

                CurlCode result2 = CurlNative.EasySetOpt(_curl, CurlOption.WriteData, this);
                if (result2 != CurlCode.Ok)
                {
                    throw new CurlException(result2, this);
                }

                CurlCode result3 = CurlNative.EasySetOpt(_curl, CurlOption.WriteFunction, WriteCallback);
                if (result3 != CurlCode.Ok)
                {
                    throw new CurlException(result3, this);
                }

                CurlCode result4 = CurlNative.EasyPerform(_curl);
                if (result4 != CurlCode.Ok)
                {
                    throw new CurlException(result4, this);
                }

                return(new ArraySegment <byte>(_buffer, 0, _offset));
            }
            finally
            {
                if (urlpointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(urlpointer);
                }
                if (useragentpointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(useragentpointer);
                }
            }
        }
Example #4
0
        public ArraySegment <byte> PostBytes(string url, string data, Encoding encoding)
        {
            IntPtr bytes = IntPtr.Zero;

            try
            {
                bytes = MarshalString.StringToNative(data, encoding, out int length);
                return(Post(url, bytes, length));
            }
            finally
            {
                bytes.Free();
            }
        }
Example #5
0
        public string PostString(string url, string data, Encoding encoding)
        {
            IntPtr bytes = IntPtr.Zero;

            try
            {
                bytes = MarshalString.StringToNative(data, encoding, out int length);
                return(ToText(Post(url, bytes, length), encoding));
            }
            finally
            {
                bytes.Free();
            }
        }
Example #6
0
        internal static CurlCode EasySetOpt(this CurlHandle handle, CurlOption option, string value)
        {
            IntPtr text = IntPtr.Zero;

            try
            {
                text = MarshalString.StringToNative(value);
                return(EasySetOpt(handle, option, text));
            }
            finally
            {
                text.Free();
            }
        }
Example #7
0
 public static string GetVersion()
 {
     return(MarshalString.Utf8ToString(CurlNative.GetVersion()));
 }
Example #8
0
        public string Post(string url, string data, Encoding encoding)
        {
            IntPtr urlpointer       = IntPtr.Zero;
            IntPtr useragentpointer = IntPtr.Zero;
            IntPtr datapointer      = IntPtr.Zero;

            try
            {
                urlpointer = MarshalString.StringToUtf8(url);
                CurlCode result = CurlNative.EasySetOpt(_curl, CurlOption.Url, urlpointer);
                if (result != CurlCode.Ok)
                {
                    throw new CurlException(result, this);
                }

                useragentpointer = MarshalString.StringToUtf8(UserAgent);
                CurlCode result1 = CurlNative.EasySetOpt(_curl, CurlOption.Useragent, useragentpointer);
                if (result1 != CurlCode.Ok)
                {
                    throw new CurlException(result1, this);
                }

                datapointer = MarshalString.StringToUtf8(data);
                CurlCode result2 = CurlNative.EasySetOpt(_curl, CurlOption.Postfields, datapointer);
                if (result2 != CurlCode.Ok)
                {
                    throw new CurlException(result2, this);
                }

                CurlCode result3 = CurlNative.EasySetOpt(_curl, CurlOption.WriteData, this);
                if (result3 != CurlCode.Ok)
                {
                    throw new CurlException(result3, this);
                }

                CurlCode result4 = CurlNative.EasySetOpt(_curl, CurlOption.WriteFunction, WriteCallback);
                if (result4 != CurlCode.Ok)
                {
                    throw new CurlException(result4, this);
                }

                CurlCode result5 = CurlNative.EasyPerform(_curl);
                if (result5 != CurlCode.Ok)
                {
                    throw new CurlException(result5, this);
                }

                return(encoding.GetString(_buffer, 0, _offset));
            }
            finally
            {
                if (urlpointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(urlpointer);
                }
                if (useragentpointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(useragentpointer);
                }
                if (datapointer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(datapointer);
                }
            }
        }
Example #9
0
 internal static string GetShareError(CurlShareCode code)
 {
     return(MarshalString.NativeToString(ShareStrError(code)));
 }
Example #10
0
 internal static string GetErrorMessage(CurlCode code)
 {
     return(MarshalString.NativeToString(EasyStrError(code)));
 }
Example #11
0
 internal static string GetVersion()
 {
     return(MarshalString.NativeToString(GetCurlVersion()));
 }