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 SkipVought 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
0
0
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.
 
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.
 
>[tt]XML_Send = xmlHttp.responseXML[/tt]
[tt][red]set[/red] XML_Send = xmlHttp.responseXML[/tt]

 
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", "[URL unfurl="true"]http://www.vbforums.com/",[/URL] False
        .send
        GetHTML = .responseText
    End With
    Set html = Nothing
End Function

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

 
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
 
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.
 
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
 
Regarding the Internet Transfer Control, here's a thread: thread708-970319
 
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.
 
<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
 
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:



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'.
 
[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:
>[tt]XML_Send = xmlHttp.responseXML[/tt]
[tt][red]set[/red] XML_Send = xmlHttp.responseXML[/tt]

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

 
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'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top