Hi all,

I have someone who's trying to POST some xml data to me using VBscript, which I'm totally unfamiliar with.

This is his code, more or less:

Dim postData As String = String.Empty
postData &= [xml code comes here]

Try
  Dim _encoding As New ASCIIEncoding
  Dim _data As Byte() = _encoding.GetBytes(_postData) 

  ' Prepare web request...
  Dim _myRequest As HttpWebRequest
  _myRequest = CType(WebRequest.Create(" destination URL"), HttpWebRequest)

  _myRequest.Method = "POST"
  _myRequest.ContentType = "text/plain"
  _myRequest.ContentLength = _data.Length
  Dim _stream As System.IO.Stream = _myRequest.GetRequestStream
  _stream.Write(_data, 0, _data.Length)
  _stream.Close()

Now my question is - do I need to do anything special to decode the data? Or does the following work:

$xml_data = $POST['data'];

Thanks in advance to anyone who can help me with this.

    You don't need anything special. POST data is POST data; it doesn't matter where it's coming from.

      greenie2600,
      thanks for replying.

      I'm just worried about this portion:

      Dim encoding As New ASCIIEncoding
      Dim
      data As Byte() = encoding.GetBytes(postData)

      What does this do? Can I use the data sent as a string? ie if I do

      $xml_data = $POST['data'];
      echo $xml_data;

      Will I get a [xml data printed on screen? Or do I need to do some decoding to read the data as a string?

        I was under the impression that POST data is always ASCII, and that any binary data transmitted as part of a POST header would have to converted to ASCII.

        I honestly don't know the answer to your question. Why not try it and see what happens?

          Thanks, will try it out and post the results here.

            Well, I tried testing this yesterday, and looks like I'm not getting anything.

            The other party says they are sending it as a data stream, anyone knows what that means? Do I need to do anything special to catch a data stream? urldecode or unserialize?

            Also, is it possible to POST data without giving it a name?

              I've finally resolved this, so I thought I'd share this with the community:

              Dim postData As String = String.Empty
              postData &= [xml code comes here]

              Try
              Dim encoding As New ASCIIEncoding
              Dim
              data As Byte() = encoding.GetBytes(postData)

              ' Prepare web request...
              Dim myRequest As HttpWebRequest
              myRequest = CType(WebRequest.Create(" destination URL"), HttpWebRequest)

              myRequest.Method = "POST"
              myRequest.ContentType = "text/plain"
              myRequest.ContentLength = data.Length
              Dim stream As System.IO.Stream = myRequest.GetRequestStream
              stream.Write(data, 0, data.Length)
              stream.Close()

              This VBScript actually sends a stream of data using FORM POST, without any variable name assigned to the data. I understand this is normal for sending XML files.

              To read the data stream, I had to use the following PHP code:

              $data = file_get_contents('php://input');

              This got the data into my variable name $data.

              Now it all works fine. 🙂

                Write a Reply...