Posting and Receiving XML

Just starting out? Need help? Post your questions and find answers here.
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Posting and Receiving XML

Post 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?
Regards

Andy
User avatar
Peter
Posts: 1197
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Posting and Receiving XML

Post 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
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Re: Posting and Receiving XML

Post by Ajm »

Thanks Peter.

What is the last argument 42 for on the httprequest?
Regards

Andy
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Posting and Receiving XML

Post by Fred »

https://en.wikipedia.org/wiki/Phrases_f ... g_.2842.29 :)

BTW, nice example Peter, straight to the point.
Ajm
Posts: 31
Joined: Wed Aug 26, 2015 1:52 pm

Re: Posting and Receiving XML

Post by Ajm »

I should have seen that coming. :lol:
Regards

Andy
Post Reply