Page 1 of 1
Posting and Receiving XML
Posted: Fri Dec 18, 2015 4:09 pm
by Ajm
Hi,
I am trying to send some xml from spiderbasic to a purebasic cgi and after processing the xml pass back some different xml.
Does anyone have an example of how to this can be done or point me in the right direction please?
Re: Posting and Receiving XML
Posted: Fri Dec 18, 2015 5:06 pm
by Peter
SpiderBasic:Code: Select all
EnableExplicit
Procedure myCallback(Success, Result$, UserData)
Debug "Success: " + Str(Success)
Debug "Result$: " + Result$
Debug "UserData: " + Str(UserData)
EndProcedure
HTTPRequest(#PB_HTTP_Post, "http://localhost/cgi-bin/myTestCgi.exe", "<hello />", @myCallback(), 42)
PureBasic (myTestCgi.exe):Code: Select all
EnableExplicit
If Not InitCGI()
End
EndIf
Define XML.s = "<nodata />"
Define BufferSize = ReadCGI()
If BufferSize
If CGIBuffer()
XML = PeekS(CGIBuffer(), BufferSize, #PB_Ascii)
EndIf
EndIf
If ParseXML(0, XML) And XMLStatus(0) = #PB_XML_Success
SetXMLNodeText(MainXMLNode(0), "from cgi")
XML = ComposeXML(0, #PB_XML_NoDeclaration)
EndIf
WriteCGIHeader("Access-Control-Allow-Origin", "*") ; to avoid cross-call-errors (replace / remove the asterisk if possible)
WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_CGI_LastHeader)
WriteCGIString(XML)
Greetings ... Peter
Re: Posting and Receiving XML
Posted: Fri Dec 18, 2015 8:32 pm
by Ajm
Thanks Peter.
What is the last argument 42 for on the httprequest?
Re: Posting and Receiving XML
Posted: Sat Dec 19, 2015 8:25 am
by Fred
Re: Posting and Receiving XML
Posted: Sat Dec 19, 2015 9:40 am
by Ajm
I should have seen that coming.
