コード例 #1
0
ファイル: CurlNative.cs プロジェクト: MichalPetryka/CurlNet
        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);
        }
コード例 #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);
        }
コード例 #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);
                }
            }
        }
コード例 #4
0
ファイル: Curl.Post.cs プロジェクト: MichalPetryka/CurlNet
        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();
            }
        }
コード例 #5
0
ファイル: Curl.Post.cs プロジェクト: MichalPetryka/CurlNet
        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();
            }
        }
コード例 #6
0
ファイル: CurlNative.cs プロジェクト: MichalPetryka/CurlNet
        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();
            }
        }
コード例 #7
0
 public static string GetVersion()
 {
     return(MarshalString.Utf8ToString(CurlNative.GetVersion()));
 }
コード例 #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);
                }
            }
        }
コード例 #9
0
ファイル: CurlNative.cs プロジェクト: MichalPetryka/CurlNet
 internal static string GetShareError(CurlShareCode code)
 {
     return(MarshalString.NativeToString(ShareStrError(code)));
 }
コード例 #10
0
ファイル: CurlNative.cs プロジェクト: MichalPetryka/CurlNet
 internal static string GetErrorMessage(CurlCode code)
 {
     return(MarshalString.NativeToString(EasyStrError(code)));
 }
コード例 #11
0
ファイル: CurlNative.cs プロジェクト: MichalPetryka/CurlNet
 internal static string GetVersion()
 {
     return(MarshalString.NativeToString(GetCurlVersion()));
 }