I have program that posts some json to a url and then tries to read the response.
Here is code from a quick test (I realize that it looks strange to go from json to a dictionary back to json, but that allowed me to diagnose a bug with the parsejson method, but that is a different matter that I will submit elsewhere):
[code] Using Xojo.Core
Using Xojo.Data
using xojo.Net
using Xojo.IO
dim s as string
dim content as text
dim f as folderitem = Xojo.IO.SpecialFolder.Documents.Child(“output.txt”)
if f <> nil and f.Exists then
Dim data As Dictionary = ParseJSON(self.TextArea1.Text.ToText)
' Convert to JSON text
Dim json As Text
json = GenerateJSON(data)
Dim data1 As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(json)
self.aNetSocket.SetRequestContent(data1, "application/x-www-form-urlencoded")
self.aNetSocket.Send("POST", "https://apitest.authorize.net/xml/v1/request.api", f)
end if [/code]
I have a couple of questions:
First, I cant get the FileRecieved event to fire unless I pass a folderitem with send. Is this the intended behavior?
Second, when I do pass a folderitem, the FileRecieved even fires and I capture it with this:
[code] Using Xojo.Core
Using Xojo.IO
Dim errorText As Text
Try
input = TextInputStream.Open(file, Xojo.Core.TextEncoding.UTF8)
dim contents as text = input.ReadAll()
Self.TextArea2.Text = contents
input.Close()
Catch e As IOException
errorText = "File IO Error: " + e.Reason
MsgBox errorText
End Try[/code]
The problem is that at the time the event fires, the folderitem supplied(file) is empty. However, once the event has returned the file is written to, thus I can’t capture the data because it is not available during the life of the event. Am I screwing something up with the timing?
And finally, is there a way to get data returned from a POST command in any other way than passing and receiving a folderitem using the Xojo.Net namespace?
Thank you.