473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP: Implementing cookies with WebRequest and WebResponse

Here's my problem...

When I use this code to hit the site in question I'm redirected to another
SSL login page. If processed successfully the page creates a cookie and
then redirects you to the original request.

However, my code cannot seem to hold onto the cookie it creates. Does
anyone know how to do this?
Everything works (SSL included) *except* for the cookies. trying to figure
that one out still.

Here is the code:
Imports System
Imports System.IO
Imports System.Net
Imports System.Threadin g
Imports System.Text.Reg ularExpressions
Imports System.Text.Enc oding
Imports System.Security .Cryptography.X 509Certificates

Public Class TrustAllCertifi catePolicy
Implements System.Net.ICer tificatePolicy
Public Function CheckValidation Result(ByVal srvPoint As
System.Net.Serv icePoint, ByVal certificate As
System.Security .Cryptography.X 509Certificates .X509Certificat e, ByVal request
As System.Net.WebR equest, ByVal certificateProb lem As Integer) _
As Boolean Implements
System.Net.ICer tificatePolicy. CheckValidation Result
Return True
End Function
End Class
Private Sub cmdGet_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles cmdGet.Click
'Create(a) 'WebRequest' object with the specified url
System.Net.Serv icePointManager .CertificatePol icy = New
TrustAllCertifi catePolicy

Dim myWebRequest As WebRequest
'myWebRequest.C redentials = myCert.TrustAll CertificatePoli cy
myWebRequest =
WebRequest.Crea te("https://sentri.us.norte l.com:8443/SENTRI/home.jsp")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse
myWebResponse = myWebRequest.Ge tResponse()
' Call method 'GetResponseStr eam' to obtain stream associated with
the response object
Dim ReceiveStream As Stream
ReceiveStream = myWebResponse.G etResponseStrea m()

Dim encode As System.Text.Enc oding
encode = GetEncoding("ut f-8")

' Pipe the stream to a higher level stream reader with the required
encoding format.
Dim readStream As New StreamReader(Re ceiveStream, encode)
'txtLog.Text = (ControlChars.C rLf + "Response stream received")
Dim read(1024) As [Char]

' Read 256 charcters at a time .
Dim count As Integer = readStream.Read (read, 0, 1024)
txtLog.Text = ""
'While count > 0
While readStream.Peek >= 0

' Dump the 256 characters on a string and display the string
onto the console.
Dim str As New [String](read, 0, count)
txtLog.Text = txtLog.Text & (str)
count = readStream.Read (read, 0, 1024)

End While
Dim str2 As New [String](read, 0, count)
txtLog.Text = txtLog.Text & (str2)
count = readStream.Read (read, 0, 1024)
'Console.WriteL ine("")

' Release the resources of stream object.
readStream.Clos e()

' Release the resources of response object.
myWebResponse.C lose()

End Sub

Nov 20 '05 #1
0 1318

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

Similar topics

6
4562
by: No_Excuses | last post by:
All, I am interested in reading the text of a web page and parsing it. After searching on this newgroup I decided to use the following: ******************************* START OF CODE ************************ String sTemp = "http://cgi3.igl.net/cgi-bin/ladder/teamsql/team_view.cgi?ladd=teamknights&num=238&showall=1"; WebRequest...
9
1946
by: Justin Engelman | last post by:
Hi, I have a website that uses an ISAPI filter that will redirect anyone going to any page on the site to an SSL login page (on a different website with the same root domain) if they do not have the appropriate session cookie already. After logging in on that page successfully they are given the cookie and redirected back to the page they...
0
337
by: Tony Archer | last post by:
Here's my problem... When I use this code to hit the site in question I'm redirected to another SSL login page. If processed successfully the page creates a cookie and then redirects you to the original request. However, my code cannot seem to hold onto the cookie it creates. Does anyone know how to do this?
0
2203
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't seem to make it work. Please point out the mistakes that I have. Thanks code............. WebRequest = WebRequest.Create(URL)...
2
3392
by: Mr Flibble | last post by:
Hey! I get a 404 from a website (this is "correct behaviour") and I'm interested in the value in the cookie "SMSESSION". The question is the following code generates an exception due to the 404. How am I still able to read the cookies even though I get an exception? Here's the code:
0
1072
by: Naga | last post by:
I am using the code below to login to a password requiring website programatically. I keep getting back the logon page. I have read some posts here and haven't found a working solution still. I don't need any proxy to connect. After seeing some posts I eeven added a cookie container, still doesn't work.I'd really appreciate a lot, if someone...
2
5960
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an application to download images using System.NET classes (webclient, webrequest) asynchronously behind proxy server. The reading method works like...
1
8176
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie to SMCHALLANGE=YES to allow me to obtain a session. I then iterate the cookie collection to extract the SMSESSION value. All is good (so far). This...
6
3334
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in the past in other places, and while the help was much appreciated, it seemed everyone just wanted to 'theoretically' explain how to do it, but when I...
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7665
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.