Click here to Skip to main content
15,905,504 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Generalproblem with windows service Pin
besah12-May-05 23:45
besah12-May-05 23:45 
QuestionHow to use the select item of listview? Pin
rushing12-May-05 23:16
rushing12-May-05 23:16 
AnswerRe: How to use the select item of listview? Pin
carlos_rocha13-May-05 0:15
carlos_rocha13-May-05 0:15 
Generalconvert hexadecimal to text Pin
AtcKit12-May-05 22:07
AtcKit12-May-05 22:07 
QuestionHow to know the right click event? Pin
rushing12-May-05 21:12
rushing12-May-05 21:12 
AnswerRe: How to know the right click event? Pin
carlos_rocha12-May-05 22:34
carlos_rocha12-May-05 22:34 
GeneralMSMQ problem Pin
nitin_ion12-May-05 20:42
nitin_ion12-May-05 20:42 
GeneralDownloading a CSV file from a password protected ( form's authentication) site. Screen Scrapig Method Pin
rvrajvarshan12-May-05 18:50
rvrajvarshan12-May-05 18:50 
Requirement:
Need to download a csv file from a password protected site. That site uses their own (form’s) authentication procedure (i.e. not Windows authentication). That site uses cookies to store the user details.

Procedure:
Currently we are trying to submit a request to the login URL with all the values (passing all the hidden parameters and etc.) and get the cookie from the response. We are trying to make use of the cookie the in our next request to the desired the file.

Problem:
The above procedure works at some times and not at all the time. Is there any thing wrong with the procedure, or is there any other easy way to do the same.
Actually I got this code sample from site only.


Code Part:



Classes needs to be included

Imports System.Net
Imports System.io
Imports System.Runtime.InteropServices

Private Sub screenScrapingCode()
Try

Dim wp As New WebProxy(sreverURL, intPORT) ' Creating proxy with server as "10.237.3.28" and port as 6050
Dim nc1 As New NetworkCredential(UserName, Password, Domain) ' Setting the login credentials for the proxy
wp.Credentials = nc1
Dim hr As HttpWebRequest
hr = WebRequest.Create(LoginURL) 'Creating the request for the login screen
hr.Proxy = wp
hr.Method = "POST"

Dim str As String ' hidden parameters and other values to be submitted as a string

str = postData
Dim cookies As New CookieContainer ' Cookie Container to have the cookie collection
hr.CookieContainer = cookies
Dim requestwriter As StreamWriter
requestwriter = New StreamWriter(hr.GetRequestStream())
requestwriter.Write(str) ' writing the form datas to the request object
requestwriter.Close()
Dim hres1 As HttpWebResponse
hres1 = hr.GetResponse()
Dim cooki As CookieCollection
Dim url As String
url = hres1.ResponseUri.ToString()
cooki = hres1.Cookies() ' getting the cookie from the other site
hres1.Close()

Dim filename As String ' path and filename to save the downloaded file
filename = "Data_file.html"
filename = stringFilepath + filename

Dim hr1 As HttpWebRequest
hr1 = WebRequest.Create(url) ' creating the request for the csv file
hr1.Proxy = wp
hr1.CookieContainer = cookies
cookies.Add(cooki) ' adding the cookie to the next request
Dim hres As HttpWebResponse
hres = hr1.GetResponse

Dim stream As System.IO.Stream
stream = hres.GetResponseStream

' writing the data into a file
Dim writeStream As New FileStream(filename, FileMode.Create, FileAccess.Write)
ReadWriteStream(stream, writeStream)
stream.Close()
writeStream.Close()

hres.Close()

Catch ex As Exception

End Try


End Sub

Private Sub ReadWriteStream(ByRef readStream As Stream, ByRef writeStream As Stream)

Dim Length As Integer = 256
Dim buffer(256) As Byte

Dim bytesRead As Integer = readStream.Read(buffer, 0, Length)

While (bytesRead > 0)
writeStream.Write(buffer, 0, bytesRead)
bytesRead = readStream.Read(buffer, 0, Length)
End While

readStream.Close()
writeStream.Close()
End Sub

Regards,
Varathu
Generalvb/winsock programming Pin
clikemoon12-May-05 18:32
clikemoon12-May-05 18:32 
Generalvb.net and ms word Pin
87612-May-05 16:58
87612-May-05 16:58 
QuestionHow to pass arraylist to the winform? Pin
rushing12-May-05 16:23
rushing12-May-05 16:23 
AnswerRe: How to pass arraylist to the winform? Pin
Scott Page20-May-05 6:57
professionalScott Page20-May-05 6:57 
GeneralRe: How to pass arraylist to the winform? Pin
rushing23-May-05 17:08
rushing23-May-05 17:08 
Generalsearch database and display data on the screen Pin
vaiology12-May-05 16:17
vaiology12-May-05 16:17 
GeneralRe: search database and display data on the screen Pin
numbrel14-May-05 11:19
numbrel14-May-05 11:19 
GeneralSystem.Security.Permissions Pin
MagicCity12-May-05 10:45
MagicCity12-May-05 10:45 
GeneralRe: System.Security.Permissions Pin
Dave Kreskowiak12-May-05 12:40
mveDave Kreskowiak12-May-05 12:40 
GeneralSending SMS in VB6 Pin
rifan12-May-05 9:54
rifan12-May-05 9:54 
GeneralRe: Sending SMS in VB6 Pin
Dave Kreskowiak12-May-05 12:31
mveDave Kreskowiak12-May-05 12:31 
GeneralRe: Sending SMS in VB6 Pin
rifan12-May-05 16:33
rifan12-May-05 16:33 
GeneralRe: Sending SMS in VB6 Pin
Dave Kreskowiak13-May-05 0:51
mveDave Kreskowiak13-May-05 0:51 
GeneralRe: Sending SMS in VB6 Pin
jonathan1512-May-05 22:54
jonathan1512-May-05 22:54 
GeneralVB.Net Module coding Pin
directred12-May-05 8:04
directred12-May-05 8:04 
GeneralRe: VB.Net Module coding Pin
Dave Kreskowiak12-May-05 8:38
mveDave Kreskowiak12-May-05 8:38 
GeneralUrgent - Drag and Drop Help Needed Pin
BritishEmpire12-May-05 6:30
BritishEmpire12-May-05 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.