409 Conflict HTTP Post/Get

In order to get information from a printer, it requires a Post with an XML , wait for the valid reply and then Get command on the same connection to get the values.
I use HTTPSocket asynchronous to do this,
and the Post works: the printer replies with status code 200 (which is supposed to happen).
But when I then use the same connection (that wa slept alive) to Get the result of my query placed in the Post,
I get a 409 Conflict in the response header.
I know this means the HTTP POST and HTTP GET are not paired, but I don’t know how to fix this.
Any suggestions?

[code]Replied=false

dim f as FolderItem
f= App.ExecutableFile.Parent.parent.child(“Resources”).child(“cmd.xml”)

dim s as text
dim l as string

dim t as TextInputStream
if f<>nil then
t=TextInputStream.Open(f)
t.Encoding=Encodings.UTF8
s=t.ReadAll.ToText
l=str(len(s))
end

dim URL as string
URL=URLField.text

MySocket.ClearRequestHeaders
MySocket.SetRequestHeader(“Host”,“10.0.1.82”)
MySocket.SetRequestHeader(“Content-Type”,“application/octet-stream”)
MySocket.SetRequestHeader(“Content-Length”,l.ToText)
MySocket.SetRequestHeader(“Connection”,“Keep-Alive”)
MySocket.SetRequestContent(s,“application/octet-stream”)

system.DebugLog “request about to be sent”

MySocket.SendRequest(“POST”, URL)

while replied=false // Pagereceived event sets replied to True
app.DoEvents // I know this is not very nice coding, but it works
wend

replied=false
system.DebugLog “Getting reply…”
MySocket.ClearRequestHeaders
MySocket.SetRequestHeader(“Host”,“10.0.1.82”)
MySocket.SetRequestHeader(“Connection”,“Keep-Alive”)
MySocket.SendRequest(“GET”,URL)

while replied=false
app.DoEvents
wend

MySocket.Disconnect
System.DebugLog “Diconnected”

[/code]

The Classic HTTPSocket is only HTTP 1.0 compliant which does not support keep-alive.

The only reason you are able to even attempt a second request is likely because you are catching the event prior to the socket closing itself.

The 409 response is the printer saying it does not understand the request. My guess is whatever the HTTPSocket is sending to the printer is not at all what you expect to be writing because it was not designed to support subsequent requests.

The new Xojo.Net.HTTPSocket is HTTP 1.1 compliant. However I do not know if it supports keep-alive. I believe Xojo is using a third party library or OS function so it may very well support it.

@Phillip Zedalis Thanks, I suspect xojo.net.httpsocket does not support keep-alive, so I am now looking into using CURLS from Monkeybreadsoftware.

You could always roll your own using a standard TCP socket, I suppose.