Posted on 2011-05-02
Last Modified: 2014-11-26
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")


    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
    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
	End If
	Set lobjXMLHTTPObj = Nothing
End Function

Open in new window

Question by:Rhayes28054
    1 Comment
    LVL 32

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
    SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now