Xojo.Net.HTTPSocket FileRecieved

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.

[quote=259803:@erin jamroz]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?
[/quote]

Yes.

[quote=259803:@erin jamroz]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?[/quote]

This sounds more like a framework bug.

The PageReceived event should fire if you aren’t downloading to a file.

Do you want me to submit it?

I cant get it to fire unless I supply a folderitem on send, which it then returns to me, which means it writes it to my system forcing the ‘download.’ To avoid this am I forced to use the classic framework for now?

That’d be appreciated, yeah.

Are you calling the correct overload of Send? That is to say, passing only two arguments instead of three.

This webinar might also be helpful for you:

HTTPSocket Webinar

Please see this report <https://xojo.com/issue/42140> that I filed in January. It was “verified” in early February. I have a feeling that this is related.

Unlike the “old” framework’s HTTP sockets, Xojo.Net.HTTPSocket’s FileRecevied event does NOT mean the file is actually usable. My solution is to fire a very short period Timer in the event, and then handle the file in the timer’s Action event.