Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML from VB6

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I will shortly be starting a project that involves sending XML over HTTPS by the POST method. This is from a VB6 Windows application running on a normal PC.

I'm not really sure where to start, but looking at some threads it seems I need to use ServerXMLHTTP.

I don't understand how this will work in practice. For example, do I need to open IE to connect or is this done by ServerXMLHTTP?

Also, I believe POST generates a response. How do I receive this? Is it immediate or must I wait for it?

Sorry I'm vague, but any help would be appreciated.
 
DrJavaJoe,

I changed the code slightly as I received a 438 error "Object doesn’t support this property or method" to:

Set domResponse = xmlHttp.responseXML
MsgBox domResponse.xml

The result was an empty message returned (I also added a Watch to check the content).

It seems there are 4 types of response available. This was the result of the ResponseText:

-? uPAnà ¼ó
Ê ãô U? j÷?¤JÜJ9Ú°i?bÖ R7¿ ²ª?Vòi? íÌ2rýÕ_è'ø`Ñ­Ø¢( §ÑX÷±boÍ
_²µ? Õî¹9¾Ö uàÝcÇ
êk .r a@ ?-??¦ÞPv?qx b ÇbÛìöU½çUý^hìÅìra¢aJÎêJ?¡5à?ü?;a ¯Ö()þ@ò«?6B.O?dÄä??ï ";47%Á{ôÙ © P?²?bz¥ ÚÛ!¦òÔ¦½?Ð÷`hª4ygRrþg??)"Íù_ rSA[`?

I would have expected that the content of the responses would have been similar, but one as text and the other contained in xml tags. There also appears to be content in ResponseBody, although I cannot read that.

Thanks.
 
<That is not negotiable---or are you pretending the contrary?---

That isn't nice. Be nice.

While clearly the responseXML property is itself an object, since it has properties of its own, I've noticed that in other cases the Set keyword isn't specifically required. An obvious example is
Code:
myADOCommand.Activeconnection = myADOConnection
So, tsuji, are you saying that your code is a "correction" because you tested it (recreated the error, fixed it by adding the set keyword), or are you saying so for other reasons?

Bob
 
What are you expecting from this server request?

From MSDN:

ResponseBody Variant array Returns the body of the response as an array.
ResponseStream IStream Returns the body of the response as an ADO Stream object.
ResponseText String Returns the body of the response as a text string.
ResponseXML XMLDocument Object Returns the body of the response as parsed by the MSXML XMLDOM parser.

So whatever you are expecting as a response will determine what you do with it. If they are returnig an Image then write the binary straight to a file.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
<From MSDN:

DrJ, can you provide the link? I couldn't find it.

Thanks,

Bob
 
DrJavaJoe, depending on the data I send, the server will either responed with an XML or text file. I am sending XML and have requested XML in return.

Based on the comments in your last post I would suggest that one problem might be that I created the XML (to send) in a string (strData) rather than a DOM document.

In the morning (I'm in the UK) I'll ascertain whether my request was actually received and processed by the server.
 
Bob:

croydon:
Check the status Property if OK it should be 200, other return codes can be found here:


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
BobRodes wrote:
>So, tsuji, are you saying that your code is a "correction" because you tested it (recreated the error, fixed it by adding the set keyword), or are you saying so for other reasons?

You gave an exmple without set keyword. I said at the responsexml you need that. Is that negotiable? That is is it that the set can be spared?

To give a correct input is already nice. Without a correct line, would the code ever work? With only one correct line, would it gurarantee the code work? You make your own judgement. There are multiple causes for a code to fail, especially interactive between client and server. Was there enough input to let people see through the screen? It's life.
 
DrJavaJoe,

I actaully found the ReadyState and Status properties on MSDN yesterday and included them in my code, as follows:

Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Dim xmlHttp As New ServerXMLHTTP50
Dim domResponse As DOMDocument50
xmlHttp.Open "POST", strServer, False, strUserName, strPassword
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.SetOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xmlHttp.send strData
If xmlHttp.ReadyState = 4 Then
If xmlHttp.Status = 200 Then
XML_Send = xmlHttp.responseText
MsgBox xmlHttp.responseText
Set domResponse = xmlHttp.responseXML
MsgBox domResponse.xml
End If
End If

The Status returned = 200 (OK) and the ReadyState = 4 (Completed), so this suggests it is working correctly.

One interesting point, the MSDN page:

states that when the ReadyState = 4, "All the data has been received, and the complete data is available in responseBody and responseText." There is no mention of responseXML.
 
Try some less ambitious settings, like login needs, to retrieve some (arbitrary) xml file in the public domain.

[I} Using post, synchronous.
[tt]
strServer="strData="<root></root>" 'absolute dummy
'xmlHttp.Open "POST", strServer, False, strUserName, strPassword
xmlHttp.Open "POST", strServer, False
'xmlHttp.setRequestHeader "Content-Type", "text/xml"
'xmlHttp.SetOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xmlHttp.send strData
[/tt]
[II] Using get, synchronous.
[tt]
strServer="strData=""
'xmlHttp.Open "POST", strServer, False, strUserName, strPassword
xmlHttp.Open "POST", strServer, False
'xmlHttp.setRequestHeader "Content-Type", "text/xml"
'xmlHttp.SetOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xmlHttp.send strData
[/tt]
The rest as what you've coded.

With some success, you might gain more confidence for more advanced secure site and with less doubt where it should not be.
 
Amendment

For [II], I forget to edit out "post" and replace it with "get" The corresponding line should be read like this.
[tt] xmlHttp.Open [red]"get"[/red], strServer, False '[II]
[/tt]
 
tsuji, thanks, I'll try it but I don't think I'll be able to connect as it is a secure server and will only accept HTTPS.

I'm not sure, but I believe the reply I received in responseText (my post of 11:52 yesterday) may be compressed XML. If so, is it possible to uncompress an XML stream? I am trying to get more information from the owners of the site.
 
I included GetAllHeaders before the send and found that the data on the remote server is held in gzip format. So, the ResponseText I am collecting is compressed.

So I now need to find a way to unzip the stream.
 
I have spent several hours trawling through the web trying to find a method of unzipping an XML stream using VB6, without luck.

I would appreciate any suggestions.
 
Have you tried:

xmlHttp.setRequestHeader("Accept-Encoding","gzip, deflate")


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
DrJavaJoe, yes. I found this a few days ago and thought it was the answer, but unfortunately not.

I read on another forum that "There is no support in any of the WinHttp or MSXML components for compression (e.g., compress the body of a large POST request)."

I hope this is not the case.




 
Is this a public or private server and data? Can you post the address and let us have a crack at it?


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Unfortunately it is at a private company.
 
<Is that negotiable? That is is it that the set can be spared?
Yes, that's exactly what I want to know. I gave an example where the Set keyword CAN be spared. I wondered if this were another place that it isn't necessary. That's why I asked you if you had tested your answer and found that it worked, or whether you were answering from what you already know. Feel free to answer at any time.

<To give a correct input is already nice.
That's true. However, you can be nice and then stop being nice. Which is what you did. However, you started being nice again after my post. Thanks for taking my advice. :)

Bob
 
I think I need to forget about using the MSXML functionality to try to uncompress the XML stream and instead write the stream to a file then uncompress it using gzip or Winzip.

That being the case, does anyone have any ideas on how I can create a file containing the compressed data without using a compression tool? The problem I see is, if I save it with a zip program, once uncompressed it will just give me my original compressed stream. If I save it as a text file, the zip program wont recognise it as compressed.

Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top