473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with HttpWebRequest and SSL

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("dat astore/settings.mdb")
Else
dsn = ConfigurationSettings.AppSettings("RemoteConnectio n") &
"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(St rXml)
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
Nov 22 '05 #1
1 1823
Often when connection to financial institutions, you have to have a client
certificate on your system. Does the bank in question require a client
certificate?

If so, see http://blogs.msdn.com/adarshk/archiv...19/187667.aspx
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Bruce Wiebe" <br****@btopenworld.com> wrote in message
news:d2**********@titan.btinternet.com...
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("dat astore/settings.mdb")
Else
dsn = ConfigurationSettings.AppSettings("RemoteConnectio n") &
"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(St rXml)
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

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
6
by: Georg | last post by:
Hello, I am trying to load a web page over a HTTP proxy with the POST method and I am using the following code: // open request (string url) HttpWebRequest httpWebRequest =...
0
by: davidpenty | last post by:
Hi there, I am having some problems with a multi-threaded asp.net seach page. My search page sends off four asynchronous http requests to four search engines then waits for the results to come...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.