With Xojo 2015 Release 2, most of the new Xojo framework is available for all project types. This includes Xojo.Net.HTTPSocket, which adds support for HTTP 1.1.
Xojo.Net.HTTPSocket works asynchronously, similar to how an asynchronous HTTPSocket works in the classic framework. So if you already use asynchronous sockets, then your code will need very little changes as shown below.
This classic framework code sends a POST request to a web service:
// Info to send Dim postData As New JSONItem postData.Value("Type") = "MovieQuotes" // Convert to JSON text Dim json As String = postData.ToString // Send data QuoteSocket1.SetRequestContent(json, "application/x-www-form-urlencoded") QuoteSocket1.Post("127.0.0.1:8080/special/quote")
This is the equivalent code using the new Xojo framework:
// Info to send Dim d As New Dictionary d.Value("Type") = "MovieQuotes" // Convert to JSON Dim json As Text = Xojo.Data.GenerateJSON(d) // Convert to MemoryBlock Dim data As MemoryBlock data = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(json) // Send data QuoteSocket1.SetRequestContent(data, "application/x-www-form-urlencoded") QuoteSocket1.Send("POST", "http://127.0.0.1:8080/special/quote")
As you can see, there is little difference with sending. To receive data back, you use the events of Xojo.Net.HTTPSocket. Again, many of these events are similar to what is on HTTPSocket, including: AuthenticationRequired, Error, HeadersReceived, PageReceived, ReceiveProgress and SendProgress.
If you are using the synchronous methods of the classic HTTPSocket, you’ll have to adapt your code to work asynchronously using the HTTPSocket events.
You can grab these examples that show you how to use GET and POST with the new HTTPSocket.