Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /CURL/CURL Mime
This example is the version from Sat, 20th Apr 2018.
Project "CURL Mime.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control TestButton Inherits PushButton
ControlInstance TestButton Inherits PushButton
EventHandler Sub Action() me.Enabled = false c = new MyCURLSMBS Thread1.run End EventHandler
End Control
Control Output Inherits TextArea
ControlInstance Output Inherits TextArea
End Control
Control TCPSocket1 Inherits TCPSocket
ControlInstance TCPSocket1 Inherits TCPSocket
EventHandler Sub DataAvailable() dim r as string = me.ReadAll(encodings.UTF8) // first chunk if left(r,4) = "POST" then me.Write "HTTP/1.1 100 Continue"+EndOfLine.Windows+EndOfLine.Windows else // getting chunks me.Write "HTTP/1.1 200 OK"+EndOfLine.Windows+"Content-Length: 0"+EndOfLine.Windows+EndOfLine.Windows end if End EventHandler
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() // add mime with data in string dim p as CURLSMimePartMBS = c.AddMimePart p.name = "Text" p.FileName = "test.txt" p.MimeType = "text/plain" p.DataString = "Hello World" // add mime with data in MemoryBlock p = c.AddMimePart dim pic as Picture = LogoMBS(200) dim jpeg as MemoryBlock = pic.GetData(pic.FormatJPEG) p.name = "Image" p.FileName = "test.jpg" p.Encoding = "base64" // p.MimeType = "image/jpeg" // set by file name p.DataMemory = jpeg // add mime with data in file p = c.AddMimePart dim file as FolderItem = SpecialFolder.Desktop.Child("test.jpg") pic.Save(file, pic.SaveAsJPEG) p.name = "File" p.File = file p.Encoding = "base64" p.FileName = file.Name p.MimeType = "image/jpeg" // set by file name // add mime with data in string for html p = c.AddMimePart p.Encoding = "quoted-printable" p.name = "Message" p.FileName = "test.html" p.MimeType = "text/html" dim lines() as string lines.Append "<html>" lines.Append "<head>" lines.Append "<title>Test</title>" lines.Append "</head>" lines.Append "<body>" lines.Append "<p>Hello World</p>" lines.Append "</body>" lines.Append "</html>" p.DataString = join(lines, EndOfLine) // finish c.FinishMime // now you can send... c.OptionURL = "" c.OptionPort = 2000 c.YieldTime = true c.OptionConnectionTimeout = 10 c.OptionVerbose = true c.CollectDebugData = true c.CollectOutputData = true c.CollectHeaderData = true c.OptionForbitReuse = true c.OptionFreshConnect = true c.OptionHTTPVersion = c.kHTTP_VERSION_1_1 dim e as integer = c.PerformMT timer1.Mode = timer.ModeSingle End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if c <> nil then if c.Outputs.Ubound = -1 then // failed, so show debug data output.Text = ReplaceLineEndings(c.DebugData, EndOfLine) else // show form data output.Text = ReplaceLineEndings(join(c.Outputs, ""), EndOfLine) end if c = nil end if TCPSocket1.Listen TestButton.Enabled = true End EventHandler
End Control
EventHandler Sub Open() TCPSocket1.port = 2000 TCPSocket1.Listen End EventHandler
Property c As MyCURLSMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
EventHandler Sub DebugMessage(infotype as integer, data as string, dataSize as Integer) if infotype = me.kINFO_DATA_OUT then Outputs.Append data end if End EventHandler
Property Outputs() As string
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS CURL Plugin.

MBS Xojo blog