OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Newbie question - passing XML using POST




Many thanks to those of you who offered advice on this.  I now have the
problem solved.  So I thought I might outline the solution (with some
relevant VB) for the list.

As several of you pointed out the Microsoft XMLHTTP object is the way to
send the XML (actually, I've been using the new MSXML3 ServerXMLHTTP for my
peer-to-peer stuff in line with Microsoft's recomendations).  The XML is
then received using the Request object from the ASPTypeLibrary

Although sending a complete DOMDocument is the easiest use of the object, it
doesn't give you much control and it's not much use if you have a
non-Microsoft platform at the other end.  But here it is anyway.

' To send ...

Dim XMLDoc As New MSXML2.DOMDocument
Dim XMLHTTPObject As New ServerXMLHTTP

XMLHTTPObject.open "POST", URL, False
XMLHTTPObject.send XMLDoc

' To Receive ...

Dim XMLDoc As New MSXML2.DOMDocument
XMLDoc.Load Request


Too Easy.  But the better way is to send and receive as a bunch of bytes (in
this example Unicode) - that way you have much more flexibility and the
power to handle cross-platform/coding etc. issues.


' To send ...


Dim XMLHTTPObject As New ServerXMLHTTP
Dim TextToSend As String
Dim ArrayPosn, TextBytes As Long
Dim TextByteArray() As Byte

' Convert it to Unicode
TextToSend = StrConv(TextToSend , vbUnicode)

' Shove it into an array of bytes
TextBytes = LenB(TextToSend)
ReDim TextByteArray(0 To TextBytes)
For ArrayPosn = 0 To TextBytes - 1
    TextByteArray(ArrayPosn) = AscB(MidB(TextToSend, ArrayPosn + 1, 1))
Next ArrayPosn

' and send it as Binary
XMLHTTPObject.open "POST", URL, False
XMLHTTPObject.send TextByteArray


' To Receive ...

Dim TextReceived As String
Dim ByteCount As Long

ByteCount = Request.TotalBytes
If Not ByteCount = 0 Then
    ' Read it and convert it back to application-manipulable text
    TextReceived = StrConv(Request.BinaryRead(Request.TotalBytes),
vbFromUnicode)
End If


Steve




> -----Original Message-----
> From: Stephen Young [mailto:steve@neon.com.au]
> Sent: Monday, March 19, 2001 5:39 PM
> To: xml-dev@lists.xml.org
> Subject: Newbie question - passing XML using POST
>
>
> Hi Guys
>
> I'm trying find a way to send and receive XML using HTTP
> POST.  You'd think
> it would be simple, but my low level programming skills are
> struggling with
> the task.
>
> I work in a Microsoft environment, and I have two methods
> that work, but
> they both involve sending the XML as an array (Safe Array) of
> bytes.  One
> sends an MSXML3 DOMDocument and the other does a unicode
> converion of the
> bytes at each end.
>
> 1) I don't imagine that either method will make it easy for
> non-Microsoft
> apps to communicate and
> 2) There's gotta be an easier way - I'm just having a mental
> block on what
> it is ;-)
>
> A simple solution is to forget using POST altogether, and
> either do the GET
> double round trip thing, or pass the XML in a querystring.
> There has to be
> a better way.
>
> I've taken a look at a few objects for the purpose (eg. MS
> SOAP stuff) but I
> don't want to limit communication methods at this early
> stage.  A simple
> method to initiate a transaction by sending an XML document is all I'm
> looking for.
>
> Any ideas?