[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 526
  • Last Modified:

HTTPS POST USING MSXML

I am trying to do an HTTP Post of a text file to a SSL server using WinHTTP. I keep getting the error "a security error occurred". I get the same error using Msxml2.ServerXMLHTTP.6.0 as well. The web srvice I am posting to provided me certificates and I installed them into the LOCAL MACHINE\Personal store. Here is the code I am using:


Public Function SendReceiveHTTP(pstrMsgType, pstrXMLReqMsg)
	Dim lobjXMLHTTPObj
	Dim lstrACKMessage
	Dim lstrURL
	Dim lintNoOfURLs
	Dim lstrINIFile
	Dim lintICtr
	Dim lintURLRetryCnt
	Dim lintURLRetryTimeGap
	Dim lstrREQMessage
	Dim gintJCtr
    Dim id
    Dim pwd
	
	Set lobjXMLHTTPObj = CreateObject("WinHttp.WinHttpRequest.5.1")
	


	lstrREQMessage = pstrXMLReqMsg
	
	
    lstrURL = ReadIni("Settings.ini", "HTTPPATH", "Path")

	LogEvent "OPENING CONNECTION AT :" & lstrURL

    id =  ReadIni("Settings.ini", "USER", "ID")
    pwd = ReadIni("Settings.ini", "USER", "PWD")
			
	
    lobjXMLHTTPObj.Open "POST", lstrURL, False
	    

    LogEvent("Logging without credentials")
			
	LogEvent "PREPARED TO SEND MESSAGE " & pstrMsgType	
    
    lobjXMLHTTPObj.setRequestHeader "Content-Type", "application/x-wmflatfile"


	
	   

	lobjXMLHTTPObj.Send lstrREQMessage
			
	LogEvent "SENT MESSAGE WITH :" & RetHttpMessage(lobjXMLHTTPObj.status)
		
	SendReceiveHTTP = lobjXMLHTTPObj.responseText     		
	
	If lobjXMLHTTPObj.status = 200 Then
		LogEvent "SendReceiveHTTP CONNECTION ATTEMPT  SUCCESSFULL"		
	else 
	LogEvent "SendReceiveHTTP CONNECTION ATTEMPT  FAILED"
    End If
		 	
	
	If lobjXMLHTTPObj.status <> 200 Then
		Logevent VbCrLf & "*************************** ABORMAL PROGRAM TERMINATION ************************************ " & VbCrLf & _
		 "HTTP ERROR NO : " & lobjXMLHTTPObj.status  & VbCrLf & _
		 "HTTP ERROR DESC : " & RetHttpMessage(lobjXMLHTTPObj.status) & VbCrLf & _
		 "HTTP ERROR URL : " & lstrURL & VbCrLf & _				
		 "*************************** ABORMAL PROGRAM TERMINATION ************************************ "  & VbCrLf
		WScript.Quit(0)		
	End If
	Set lobjXMLHTTPObj = Nothing
	
End Function

Open in new window

0
Rhayes28054
Asked:
Rhayes28054
1 Solution
 
shalomcCommented:
You have to explicitly specify which user certificate to use.

This article shows how to use WinHttpSetOption to specify a certificate from the cert store.

http://msdn.microsoft.com/en-us/library/aa384076(v=vs.85).aspx

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now