I am converting my old HTTPSOCKETs to Xojo.net.HttpSockets . Should I be encoding all the new form data with EncodeURLComponent?
The old code worked fine without extra encoding, but the new socket does not send the base64 data the same way. Did setFormData handle that for us in the old socket? I thought the old socket used the x-www-form-urlencoded type.
Dim form as New Dictionary
form.value("name") = "picture name"
form.value("base64img") = app.imageToBase64( SpecialFolder.Desktop.Child( "test.jpg" ) )
// old way worked fine this way, no encodeURLComponent necessary:
'SocketProject.setFormData form
'SocketProject.post( "http://www.myserver.com/scripts/expectingBase64imageAndName.php")
//new socket needs the EncodeURLComponent on the base64 data.
//dictionary form is being passed to a method of the subclassed Xojo.net.HttpsSocket
Dim postData AS Text
For i As Integer = 0 To form.Count - 1
Dim baseStr As Text = form.Key(i).StringValue.ToText +"=" +Trim(form.Value(form.Key(i)).StringValue).ToText
if form.Key(i).StringValue = "base64img" then
baseStr = form.Key(i).StringValue.ToText +"=" +EncodeURLComponent(Trim(form.Value(form.Key(i)).StringValue)).ToText
end
If i < form.count - 1 Then // We won't add a "&" to the last key/value pair
postData = postData + baseStr + "&"
Else
postData = postData + baseStr
End If
Next
Dim data As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(postData)
SetRequestContent(data, "application/x-www-form-urlencoded")
Send("POST", "http://www.myserver.com/scripts/expectingBase64imageAndName.php")