public static void Main(String[] args) { try { Curl.GlobalInit(CurlInitFlag.All); // <form action="http://mybox/cgi-bin/myscript.cgi // method="post" enctype="multipart/form-data"> using (var mf = new CurlHttpMultiPartForm()) { mf.AddSection(CurlFormOption.CopyName, "frmUsername", CurlFormOption.CopyContents, "testtcc", CurlFormOption.End); // <input name="frmPassword"> mf.AddSection(CurlFormOption.CopyName, "frmPassword", CurlFormOption.CopyContents, "tcc", CurlFormOption.End); // <input name="frmFileOrigPath"> mf.AddSection(CurlFormOption.CopyName, "frmFileOrigPath", CurlFormOption.CopyContents, args[1], CurlFormOption.End); // <input name="frmFileDate"> mf.AddSection(CurlFormOption.CopyName, "frmFileDate", CurlFormOption.CopyContents, "08/01/2004", CurlFormOption.End); // <input type="File" name="f1"> mf.AddSection(CurlFormOption.CopyName, "f1", CurlFormOption.File, args[1], CurlFormOption.ContentType, "application/binary", CurlFormOption.End); using (var easy = new CurlEasy()) { easy.DebugFunction = OnDebug; easy.Verbose = true; easy.ProgressFunction = OnProgress; easy.Url = args[0]; easy.HttpPost = mf; easy.Perform(); } } Curl.GlobalCleanup(); } catch (Exception ex) { Console.WriteLine(ex); } Console.ReadLine(); }
private static void Main(string[] args) { var bits = IntPtr.Size*8; Console.WriteLine("Test curl {0} bit", bits); Curl.GlobalInit(CurlInitFlag.All); Console.WriteLine("Curl Version: {0}\n", Curl.Version); const string postData = "parm1=12345&parm2=Hello+world%21"; var postLength = postData.Length; Console.WriteLine("\n========== TEST 1 HttpWebRequest ============"); var request = (HttpWebRequest) WebRequest.Create(TEST_URL); var data = Encoding.ASCII.GetBytes(postData); request.UserAgent = "HttpWebRequest"; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse) request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); Console.WriteLine(responseString); try { Console.WriteLine("\n========== TEST 2 CurlEasy PostFields ============"); using (var easy = new CurlEasy()) { easy.WriteFunction = OnWriteData; easy.WriteData = null; easy.PostFields = postData; easy.PostFieldSize = postLength; easy.UserAgent = "CurlEasy PostFields"; easy.FollowLocation = true; easy.Url = TEST_URL; easy.Post = true; var code = easy.Perform(); } Console.WriteLine("\n========== TEST 3 CurlEasy HttpPost ============"); var mf = new CurlHttpMultiPartForm(); mf.AddSection(CurlFormOption.CopyName, "parm1", CurlFormOption.CopyContents, "12345", CurlFormOption.End); mf.AddSection(CurlFormOption.CopyName, "parm2", CurlFormOption.CopyContents, "Hello world!", CurlFormOption.End); using (var easy = new CurlEasy()) { easy.WriteFunction = OnWriteData; easy.WriteData = null; easy.UserAgent = "CurlEasy HttpPost"; easy.FollowLocation = true; easy.Url = TEST_URL; easy.HttpPost = mf; var code = easy.Perform(); } Curl.GlobalCleanup(); } catch (Exception ex) { Console.WriteLine(ex); } Console.WriteLine("\nPress <ENTER> to exit..."); Console.ReadLine(); }