473,394 Members | 1,694 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,394 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 1828
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.