Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <exception cref="System.InvalidOperationException">This is thrown
 /// if <see cref="Curl"/> hasn't bee properly initialized.</exception>
 /// <exception cref="System.NullReferenceException">This is thrown if
 /// the native <c>CURL*</c> handle wasn't created successfully.</exception>
 public Easy()
 {
     Curl.EnsureCurl();
     m_pCURL = External.curl_easy_init();
     EnsureHandle();
     External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_NOPROGRESS,
                               IntPtr.Zero);
     m_pMyStrings     = External.curl_shim_alloc_strings();
     m_pfWrite        = null;
     m_privateData    = null;
     m_writeData      = null;
     m_pfRead         = null;
     m_readData       = null;
     m_pfProgress     = null;
     m_progressData   = null;
     m_pfDebug        = null;
     m_debugData      = null;
     m_pfHeader       = null;
     m_headerData     = null;
     m_pfSSLContext   = null;
     m_sslContextData = null;
     m_pfIoctl        = null;
     m_ioctlData      = null;
     InstallDelegates();
 }
Exemplo n.º 2
0
        private void btn_Post_Click(object sender, EventArgs e)
        {
            IntPtr m_pCURL = External.curl_easy_init();

            CURLcode retCode = CURLcode.CURLE_OK;

            retCode = External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_URL, Marshal.StringToCoTaskMemAnsi("https://account.storepos.cn/UnifiedPay/Mch_Reg"));
            retCode = External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_POSTFIELDS, Marshal.StringToCoTaskMemAnsi($"a={Uri.EscapeDataString("我是中文")}&b={Uri.EscapeDataString("i am English")}"));
            retCode = External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_USERAGENT, Marshal.StringToCoTaskMemAnsi("我是尹自强的工具"));
            retCode = External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_SSL_VERIFYHOST, (IntPtr)0);
            retCode = External.curl_easy_setopt(m_pCURL, CURLoption.CURLOPT_SSL_VERIFYPEER, (IntPtr)0);

            CURLcode res = External.curl_easy_perform(m_pCURL);

            if (res != CURLcode.CURLE_OK)
            {
                // Error
            }

            this.txt_Result.AppendText(res.ToString());
            this.txt_Result.AppendText(Environment.NewLine);

            External.curl_easy_cleanup(m_pCURL);

            return;

            //try
            //{
            //    using (var pro = new Process())
            //    {
            //        var str_form = $"a={Uri.EscapeDataString("我是中文")}&b={Uri.EscapeDataString("i am English")}";
            //        var str_cmd = $"-H \"Content-Type:application/x-www-form-urlencoded;charset=UTF-8\" --user-agent \"YZQ.curl\" --data \"{str_form}\" https://account.storepos.cn/UnifiedPay/Mch_Reg";

            //        pro.StartInfo.FileName = Path.Combine(Environment.CurrentDirectory, "Lib\\curl.exe");
            //        pro.StartInfo.UseShellExecute = false;
            //        pro.StartInfo.RedirectStandardInput = true;
            //        pro.StartInfo.RedirectStandardOutput = true;
            //        pro.StartInfo.RedirectStandardError = true;
            //        pro.StartInfo.CreateNoWindow = true;
            //        pro.StartInfo.Arguments = str_cmd;
            //        //pro.StartInfo.StandardInputEncoding = Encoding.UTF8;
            //        pro.StartInfo.StandardOutputEncoding = Encoding.UTF8;
            //        pro.Start();
            //        pro.StandardInput.AutoFlush = true;

            //        //获取cmd窗口的输出信息
            //        var output = pro.StandardOutput.ReadToEnd();

            //        pro.WaitForExit();
            //        pro.Close();

            //        this.AppendResult(string.Format("【FormData】:{0}", str_form));
            //        this.AppendResult(string.Format("【Arguments】:{0}", str_cmd));
            //        this.AppendResult(string.Format("【Response】:{0}", output));
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}
        }