Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

croydon (Programmer) (OP)
16 Dec 05 8:51
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.
Sheco (Programmer)
16 Dec 05 9:41
The following links are more from a server script perspective but you can just as well instatiate the objects in vb6.

http://www.15seconds.com/issue/991125.htm

http://www.4guysfromrolla.com/webtech/110100-1.shtml

croydon (Programmer) (OP)
20 Dec 05 4:31
Sheco, thanks for the reply.

I have actually found a link that relates more to VB6:

http://www.developerfusion.co.uk/show/3272/2/

From this it looks as though the send and receive processes can be run from VB6 without opening IE.
croydon (Programmer) (OP)
4 Jan 06 10:00
I got a bit further with this and am reaching the target server. The code is below:

Dim xmlHttp As New ServerXMLHTTP50
xmlHttp.Open "POST", strServer, False
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.send strData
XML_Send = xmlHttp.responseXML

The problem I have now is that I get the error -2147012851 "The certificate authority is invalid or incorrect".

I cannot find a way to accept or ignore the certificate. Any suggestions would be appreciated.
tsuji (TechnicalUser)
4 Jan 06 10:10
>XML_Send = xmlHttp.responseXML
set XML_Send = xmlHttp.responseXML

dglienna (Programmer)
4 Jan 06 10:34
You could also use Microsoft XML v4.0, which was designed to parse XML.  You can download it from Microsoft's web site.

CODE

Option Explicit
' Add a reference to Microsoft XML v4.0

Private Sub Form_Load()
GetHTML
MsgBox GetHTML
End Sub

Private Function GetHTML() As String
    Dim html As IXMLHTTPRequest
    Set html = CreateObject("Microsoft.XMLHTTP")
    With html
        .Open "GET", "http://www.vbforums.com/", False
        .send
        GetHTML = .responseText
    End With
    Set html = Nothing
End Function

David

croydon (Programmer) (OP)
4 Jan 06 11:06
Thanks for the responses.

Dave, with MSXML 4.0 would I be able to "POST" to "HTTPS"?

I tried your sample code with a few alterations as follows:

Dim getHtml As String
Dim html As IXMLHTTPRequest
Set html = CreateObject("Microsoft.XMLHTTP")
With html
    .Open "POST", strServer, False
    .send strData
    getHtml = .responseText
End With
Set html = Nothing
MsgBox getHtml

I get an error -2146697208 "The download of the specified resource has failed". This is on the .send line, where I am sending the XML.
croydon (Programmer) (OP)
4 Jan 06 11:24
tsuji, I tried using SET and using .ResponseText to return a string but I received the same "certificate invalid" error. This was on the .send line.

dglienna (Programmer)
4 Jan 06 11:45
I don't think the MSXML control is for posting data.  It is just used to interact with XML documents, just reading them.
You don't have to do string manipulation.  There are samples in the download for the control.  There are also different versions available, with 4.0 being the most current.

David

croydon (Programmer) (OP)
4 Jan 06 12:02
dglienna,

All I need to do is send an XML document to a specified site (it must be using "POST" and "HTTPS"), and collect an XML response.

If MSXML does not provide this functionality, what would you suggest?

Earlier today I was able to connect using ServerXMLHTTP but had the problem with an "invalid certificate". Have you any ideas for resolving this?

Thanks.
dglienna (Programmer)
4 Jan 06 12:23
I think the Internet Transfer Control would be your best bet.  You can input a username and password, and then execute a command.  I've never tried sending data with it, though.

David

BobRodes (Instructor)
4 Jan 06 13:03
Regarding the Internet Transfer Control, here's a thread: thread708-970319
croydon (Programmer) (OP)
4 Jan 06 16:14
I think the Internet Transfer Control is a non-starter. I frequently use this for FTP.

MSXML seems to be designed to send XML over HTTP and collect responses.

I just need to overcome the problem with the certificate.
 
BobRodes (Instructor)
4 Jan 06 16:27
<I think the Internet Transfer Control is a non-starter.

I had a lot of trouble with it too, as the thread documents, and gives an API-based alternative using wininet.dll.

Bob
DrJavaJoe (Programmer)
4 Jan 06 19:59
Try this and let us know if it works:

Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Dim xmlHttp As New ServerXMLHTTP50
xmlHttp.Open "POST", strServer, False
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xmlHttp.send strData
XML_Send = xmlHttp.responseXML

More info:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/0e401d47-5df0-47e7-bf5f-7ed36c865b8d.asp


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'.

tsuji (TechnicalUser)
4 Jan 06 20:50
[1] dglienna wrote:
>I don't think the MSXML control is for posting data
Don't just think, read and do. The statement is wrong.

[2] DrJavaJoe wrote:
>XML_Send = xmlHttp.responseXML
set XML_Send = xmlHttp.responseXML

I'd posted the correction already. That is not negotiable---or are you pretending the contrary?---what ever multiple cause existing to make the code fail.
dglienna (Programmer)
4 Jan 06 21:55
I've seen code that posts images to a website using Winsock, and that may work, also.  I said what I did because I've never had a need to post data to a secured site, and wouldn't want to steer Bob in the wrong direction. smile

-David
2006 Microsoft Valued Professional (MVP)

keenanbr (Programmer)
5 Jan 06 6:04
croydon (Programmer) (OP)
5 Jan 06 6:29
DrJavaJoe,

I tried your suggestion and this looks to have overcome the certificate problem (I think). The next problem I have is to get the XML response.

Using XML_Send = xmlHttp.responseText I get a response but it is just 3 lines of unreadable characters. When I use XML_Send = xmlHttp.responseXML I get error 438 "Object doesn’t support this property or method". So I changed this line to XML_Send = xmlHttp.responseXML.XML and now get an empty response. Could this be because XML_Send is a string?

Tsuji,

As I mentioned previously, the problem certificate error occurred before the program reached the XML_Send = xmlHttp.responseXML line. As I have progressed a little further now I have included the SET and get the error "Object required". What type of object should XML_Send be?

Keenanbr,

I will read this document now. Thanks.


Thank you all for your help with this.

DrJavaJoe (Programmer)
5 Jan 06 11:19
Try this

Dim XML_Send As DOMDocument50
Set XML_Send = xmlHttp.responseXML

msgbox XML_Send.xml


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'.

croydon (Programmer) (OP)
5 Jan 06 11:52
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.
BobRodes (Instructor)
5 Jan 06 12:26
<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
DrJavaJoe (Programmer)
5 Jan 06 15:25
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'.

BobRodes (Instructor)
5 Jan 06 16:14
<From MSDN:

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

Thanks,

Bob
croydon (Programmer) (OP)
5 Jan 06 16:39
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.
DrJavaJoe (Programmer)
5 Jan 06 18:03
Bob:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmes2k/html/devwebapps.asp

croydon:
Check the status Property if OK it should be 200, other return codes can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/f6de15fc-72e9-418e-b275-d94b0b2045de.asp


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 (Instructor)
5 Jan 06 18:43
Thanks DrJ.  :)
tsuji (TechnicalUser)
5 Jan 06 22:08
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.
croydon (Programmer) (OP)
6 Jan 06 9:32
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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/89b68625-db6d-41b3-91e8-1f0e106ff255.asp

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.




tsuji (TechnicalUser)
6 Jan 06 10:49
Try some less ambitious settings, like login needs, to retrieve some (arbitrary) xml file in the public domain.

[I} Using  post, synchronous.

strServer="http://www.xslmaker.com/articles.xml"
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

[II] Using get, synchronous.

strServer="http://www.xslmaker.com/articles.xml"
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

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.
tsuji (TechnicalUser)
6 Jan 06 10:52
Amendment

For [II], I forget to edit out "post" and replace it with "get" The corresponding line should be read like this.
    xmlHttp.Open "get", strServer, False    '[II]
croydon (Programmer) (OP)
6 Jan 06 11:29
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.
croydon (Programmer) (OP)
9 Jan 06 3:47
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.    
croydon (Programmer) (OP)
9 Jan 06 9:29
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.
  
DrJavaJoe (Programmer)
9 Jan 06 11:33
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'.

croydon (Programmer) (OP)
9 Jan 06 15:25
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.




DrJavaJoe (Programmer)
9 Jan 06 15:42
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'.

croydon (Programmer) (OP)
9 Jan 06 15:50
Unfortunately it is at a private company.
BobRodes (Instructor)
9 Jan 06 16:35
<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
croydon (Programmer) (OP)
10 Jan 06 11:17
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?
croydon (Programmer) (OP)
20 Jan 06 11:08
For anyone that is interested, the following code overcomes the problem I had with the compressed XML.

It Sends the XML contained in the file named in strSend, then places the Response in the file named in strReceive as well as in the string XML_Send. The compressed XML is unzipped in the process so comes back as text:

Set xmlhttp = New MSXML2.XMLHTTP40
Set adostream = New ADODB.Stream

xmlhttp.Open "GET", strServer, False
xmlhttp.send
    
'Open a connection to the https url
xmlhttp.Open "POST", strServer, False
    
adostream.Open
adostream.Type = adTypeBinary
adostream.LoadFromFile strSend
filebytes = adostream.Read
adostream.Close
    
'Send the document request file
xmlhttp.send filebytes

'Get response
adostream.Open
adostream.Type = adTypeBinary
adostream.Position = 0
adostream.SetEOS
adostream.Write xmlhttp.responseBody
adostream.SaveToFile strReceive, adSaveCreateOverWrite
adostream.Close

XML_Send = xmlhttp.responseText

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close