B
Bruce Wiebe
hi all
Im having a big problem connecting to a SSL site (HSBC Bank) using
httpWebRequest. what i need to do is connet to the site and pass over an xml
string and read the response. Im pretty sure that ive created the connection
etc properly however when i attempt to do the post the page collapses in a
heap when it tries to get the request stream with an error of
The Function Completed Successfully, but must be called again to complete
the content
Exception Details: System.ComponentModel.Win32Exception: The Function
Completed Successfully, but must be called again to complete the content
and in the stack trace
[Webexception: The underlying connection was closed: Could not establish
secure channel for SSL/TLS.}
ive posted the code that causes this below
If there is anyone out there that can help at all it would be most
appreciated as the client im doing this for is getting a little fed up with
the problems that we have had with the bank and the time that this is taking
to develop
_____________________________________________-Code Starts Here
________________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'get the settings from the database
Dim dsn As String
If remote = "False" Then
dsn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
System.Web.HttpContext.Current.Server.MapPath("datastore/settings.mdb")
Else
dsn = ConfigurationSettings.AppSettings("RemoteConnection") &
"Settings.mdb"
End If
Dim myconnection As OleDbConnection
Dim mycommand As OleDbCommand
Dim sql As String
Dim myreader As OleDbDataReader
Dim username As String
Dim password As String
Dim clientID As String
Dim Url As String
Dim price As String = Label3.Text.Remove(0, 1)
sql = "select * from hsbc where id=1"
myconnection = New OleDbConnection(dsn)
myconnection.Open()
mycommand = New OleDbCommand(sql, myconnection)
myreader = mycommand.ExecuteReader
While myreader.Read
username = myreader.Item("xmlstore").ToString
password = myreader.Item("StrPassword").ToString
clientID = myreader.Item("ClientID").ToString
Url = myreader.Item("hsbcpath").ToString
End While
myreader.Close()
myconnection.Close()
'build the string
Dim StrXml As String
StrXml = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf
'the rest of the xml string has been removed for clarity
'create the web request
Dim lohttp As HttpWebRequest = CType(WebRequest.Create(Url),
HttpWebRequest)
lohttp.KeepAlive = False
lohttp.Timeout = 10000
lohttp.MaximumAutomaticRedirections = 30
'send the data to the server
lohttp.Method = "POST"
Dim lbPostBuffer As Byte() =
System.Text.Encoding.GetEncoding(1252).GetBytes(StrXml)
lohttp.ContentLength = lbPostBuffer.Length
lohttp.ContentType = "application/x-www-form-urlencoded"
'the line below here is where the error occurs
Dim lopostdata As Stream = lohttp.GetRequestStream()
lopostdata.Write(lbPostBuffer, 0, lbPostBuffer.Length)
lopostdata.Close()
Response.Write(lbPostBuffer.Length)
'read the response from the server
Dim lowebresponse As HttpWebResponse = CType(lohttp.GetResponse(),
HttpWebResponse)
Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
Dim loResponseStream As New
StreamReader(lowebresponse.GetResponseStream(), enc)
Dim lchtml As String = loResponseStream.ReadToEnd()
lowebresponse.Close()
loResponseStream.Close()
'lchtml holds the values of the response so we can process and view
the response
'and do what we need to accordingly
Response.Write(lchtml)
End Sub
Im having a big problem connecting to a SSL site (HSBC Bank) using
httpWebRequest. what i need to do is connet to the site and pass over an xml
string and read the response. Im pretty sure that ive created the connection
etc properly however when i attempt to do the post the page collapses in a
heap when it tries to get the request stream with an error of
The Function Completed Successfully, but must be called again to complete
the content
Exception Details: System.ComponentModel.Win32Exception: The Function
Completed Successfully, but must be called again to complete the content
and in the stack trace
[Webexception: The underlying connection was closed: Could not establish
secure channel for SSL/TLS.}
ive posted the code that causes this below
If there is anyone out there that can help at all it would be most
appreciated as the client im doing this for is getting a little fed up with
the problems that we have had with the bank and the time that this is taking
to develop
_____________________________________________-Code Starts Here
________________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
'get the settings from the database
Dim dsn As String
If remote = "False" Then
dsn = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
System.Web.HttpContext.Current.Server.MapPath("datastore/settings.mdb")
Else
dsn = ConfigurationSettings.AppSettings("RemoteConnection") &
"Settings.mdb"
End If
Dim myconnection As OleDbConnection
Dim mycommand As OleDbCommand
Dim sql As String
Dim myreader As OleDbDataReader
Dim username As String
Dim password As String
Dim clientID As String
Dim Url As String
Dim price As String = Label3.Text.Remove(0, 1)
sql = "select * from hsbc where id=1"
myconnection = New OleDbConnection(dsn)
myconnection.Open()
mycommand = New OleDbCommand(sql, myconnection)
myreader = mycommand.ExecuteReader
While myreader.Read
username = myreader.Item("xmlstore").ToString
password = myreader.Item("StrPassword").ToString
clientID = myreader.Item("ClientID").ToString
Url = myreader.Item("hsbcpath").ToString
End While
myreader.Close()
myconnection.Close()
'build the string
Dim StrXml As String
StrXml = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf
'the rest of the xml string has been removed for clarity
'create the web request
Dim lohttp As HttpWebRequest = CType(WebRequest.Create(Url),
HttpWebRequest)
lohttp.KeepAlive = False
lohttp.Timeout = 10000
lohttp.MaximumAutomaticRedirections = 30
'send the data to the server
lohttp.Method = "POST"
Dim lbPostBuffer As Byte() =
System.Text.Encoding.GetEncoding(1252).GetBytes(StrXml)
lohttp.ContentLength = lbPostBuffer.Length
lohttp.ContentType = "application/x-www-form-urlencoded"
'the line below here is where the error occurs
Dim lopostdata As Stream = lohttp.GetRequestStream()
lopostdata.Write(lbPostBuffer, 0, lbPostBuffer.Length)
lopostdata.Close()
Response.Write(lbPostBuffer.Length)
'read the response from the server
Dim lowebresponse As HttpWebResponse = CType(lohttp.GetResponse(),
HttpWebResponse)
Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
Dim loResponseStream As New
StreamReader(lowebresponse.GetResponseStream(), enc)
Dim lchtml As String = loResponseStream.ReadToEnd()
lowebresponse.Close()
loResponseStream.Close()
'lchtml holds the values of the response so we can process and view
the response
'and do what we need to accordingly
Response.Write(lchtml)
End Sub