Xojo.Net.HTTPSocket.SetRequestContent
From Xojo Documentation
Method
Xojo.Net.HTTPSocket.SetRequestContent(data As Xojo.Core.MemoryBlock, mimeType As Text)
Supported for all project types and targets.
Supported for all project types and targets.
Sets the content data and content type to be sent to the server.
Sample Code
Sends a POST request, converting JSON data to a MemoryBlock before sending:
Using Xojo.Core
Using Xojo.Data
// Simple data in a Dictionary
Var info As New Dictionary
info.Value("ID") = 123456
// Convert to JSON text
Var json As Text
json = GenerateJSON(info)
// Convert to MemoryBlock
Var data As MemoryBlock
data = TextEncoding.UTF8.ConvertTextToData(json)
mySocket.SetRequestContent(data, "application/json")
mySocket.Send("POST", "http://127.0.0.1:8080/GetCustomer")
Using Xojo.Data
// Simple data in a Dictionary
Var info As New Dictionary
info.Value("ID") = 123456
// Convert to JSON text
Var json As Text
json = GenerateJSON(info)
// Convert to MemoryBlock
Var data As MemoryBlock
data = TextEncoding.UTF8.ConvertTextToData(json)
mySocket.SetRequestContent(data, "application/json")
mySocket.Send("POST", "http://127.0.0.1:8080/GetCustomer")
To send form information, you build the text yourself:
Using Xojo.Core
Using Xojo.Data
// Build form text
Var formText As Text = "firstName=Bob&lastName=Roberts"
// Convert to MemoryBlock
Var postData As Xojo.Core.MemoryBlock
postData = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(formText)
// POST it
MyHttpSocket.SetRequestContent(postData, "application/x-www-form-urlencoded")
MyHttpSocket.Send("POST", "http://www.webserviceurl.com")
Using Xojo.Data
// Build form text
Var formText As Text = "firstName=Bob&lastName=Roberts"
// Convert to MemoryBlock
Var postData As Xojo.Core.MemoryBlock
postData = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(formText)
// POST it
MyHttpSocket.SetRequestContent(postData, "application/x-www-form-urlencoded")
MyHttpSocket.Send("POST", "http://www.webserviceurl.com")