need help https and vb.net

hi,

i am new to this board so excuse me if my english is not so good.
i have an assignment to write a program
that can download file from https protocol.
the problem is how can i pass the username and password?
thanks.

Comments

  • [b][red]This message was edited by DrMarten at 2006-9-28 14:3:45[/red][/b][hr]
    : hi,
    :
    : i am new to this board so excuse me if my english is not so good.
    : i have an assignment to write a program
    : that can download file from https protocol.
    : the problem is how can i pass the username and password?
    : thanks.

    ======================================================================
    Hi,

    I tried the following too and it didn't work. :-(
    [code]
    Public Sub test()
    Dim startInfo As New ProcessStartInfo("IExplore.exe")
    'startInfo.WindowStyle = ProcessWindowStyle.Minimized

    Process.Start(startInfo)

    startInfo.Arguments = ("http://outranet.scm.tees.ac.uk/pfp/")

    Process.Start(startInfo)
    SendKeys.Send("myUserName" + "{Enter}")
    SendKeys.Send("myPassWord" + "{Enter}")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    test()
    End Sub
    [/code]

    Anyone any ideas please?


    Regards,

    Dr M.

  • : [b][red]This message was edited by DrMarten at 2006-9-28 14:3:45[/red][/b][hr]
    : : hi,
    : :
    : : i am new to this board so excuse me if my english is not so good.
    : : i have an assignment to write a program
    : : that can download file from https protocol.
    : : the problem is how can i pass the username and password?
    : : thanks.
    :
    : ======================================================================
    : Hi,
    :
    : I tried the following too and it didn't work. :-(
    : [code]
    : Public Sub test()
    : Dim startInfo As New ProcessStartInfo("IExplore.exe")
    : 'startInfo.WindowStyle = ProcessWindowStyle.Minimized
    :
    : Process.Start(startInfo)
    :
    : startInfo.Arguments = ("http://outranet.scm.tees.ac.uk/pfp/")
    :
    : Process.Start(startInfo)
    : SendKeys.Send("myUserName" + "{Enter}")
    : SendKeys.Send("myPassWord" + "{Enter}")
    :
    : End Sub
    :
    : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    : test()
    : End Sub
    : [/code]
    :
    : Anyone any ideas please?
    :
    :
    : Regards,
    :
    : Dr M.
    :
    :
    Hi folks,
    this would take a little more work.

    [code] [green]'1st - you'll need System.Net.WebClient to download file
    [/green]
    Dim wc As New Net.WebClient
    [green]2nd - you're supposed to decide whether you belive remote ssl certificate, let's blindly say we do :)
    [/green]
    Dim CredCache As New Net.CredentialCache
    [green]3rd - authenticate with login and password. This is example for Digest algorithm in domain. Ask msdn for further details.[/green]
    CredCache.Add(New Uri("https://asdf.com"), "Digest", New Net.NetworkCredential("YourLoginName", "YourPassword", "DomainName"))
    wc.Credentials = CredCache
    [green]4th - download the file and what ever else..[/green]
    wc.DownloadFile("https://url.com/file.ext", "c:somewhere.ext")
    [/code]
    [RED]BUD[/RED] there's a little difference between .NET 1.1 and .NET 2.0 in part "2nd".
    In .NET 2.0 (that I used for origin of this code), you do not have to care about validity of SSL certificate, there's a method delegate that you should set to addressof your method which could verify the certificate. If you do not this, the certificate is (blindly) supposed to be correct.
    In .NET 1.1, you have to create class implementing ICertificatePolicy interface and it's CheckValidationResult method to decide, if the certificate is fake or not..
    [code]
    Public Class CertificateValidator
    Implements Net.ICertificatePolicy

    Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
    Return True [green]'Do I care? For this example I do not. But if there would be my money or privaci in bet, I definitelly WOULD![/green]
    End Function
    End Class[/code]
    You also have to set CertificatePolicy to your class (before downloading that file) like this
    [code]ServicePointManager.CertificatePolicy = New CertificateValidator()[/code]

    I didn't test this code as is (because of copying it from my older project) so there may be some little mistakes (like that url could be without https:// at the beginning etc, but the concept should work)

    Hope this helps..

    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


  • : : : hi,
    : : :
    : : : i am new to this board so excuse me if my english is not so good.
    : : : i have an assignment to write a program
    : : : that can download file from https protocol.
    : : : the problem is how can i pass the username and password?
    : : : thanks.
    : :
    : : ======================================================================
    : : Hi,
    : :
    : : I tried the following too and it didn't work. :-(
    : : [code]
    : : Public Sub test()
    : : Dim startInfo As New ProcessStartInfo("IExplore.exe")
    : : 'startInfo.WindowStyle = ProcessWindowStyle.Minimized
    : :
    : : Process.Start(startInfo)
    : :
    : : startInfo.Arguments = ("http://outranet.scm.tees.ac.uk/pfp/")
    : :
    : : Process.Start(startInfo)
    : : SendKeys.Send("myUserName" + "{Enter}")
    : : SendKeys.Send("myPassWord" + "{Enter}")
    : :
    : : End Sub
    : :
    : : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    : : test()
    : : End Sub
    : : [/code]
    : :
    : : Anyone any ideas please?
    : :
    : :
    : : Regards,
    : :
    : : Dr M.
    : :
    : :
    : Hi folks,
    : this would take a little more work.
    :
    : [code] [green]'1st - you'll need System.Net.WebClient to download file
    : [/green]
    : Dim wc As New Net.WebClient
    : [green]2nd - you're supposed to decide whether you belive remote ssl certificate, let's blindly say we do :)
    : [/green]
    : Dim CredCache As New Net.CredentialCache
    : [green]3rd - authenticate with login and password. This is example for Digest algorithm in domain. Ask msdn for further details.[/green]
    : CredCache.Add(New Uri("https://asdf.com"), "Digest", New Net.NetworkCredential("YourLoginName", "YourPassword", "DomainName"))
    : wc.Credentials = CredCache
    : [green]4th - download the file and what ever else..[/green]
    : wc.DownloadFile("https://url.com/file.ext", "c:somewhere.ext")
    : [/code]
    : [RED]BUD[/RED] there's a little difference between .NET 1.1 and .NET 2.0 in part "2nd".
    : In .NET 2.0 (that I used for origin of this code), you do not have to care about validity of SSL certificate, there's a method delegate that you should set to addressof your method which could verify the certificate. If you do not this, the certificate is (blindly) supposed to be correct.
    : In .NET 1.1, you have to create class implementing ICertificatePolicy interface and it's CheckValidationResult method to decide, if the certificate is fake or not..
    : [code]
    : Public Class CertificateValidator
    : Implements Net.ICertificatePolicy
    :
    : Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
    : Return True [green]'Do I care? For this example I do not. But if there would be my money or privaci in bet, I definitelly WOULD![/green]
    : End Function
    : End Class[/code]
    : You also have to set CertificatePolicy to your class (before downloading that file) like this
    : [code]ServicePointManager.CertificatePolicy = New CertificateValidator()[/code]
    :
    : I didn't test this code as is (because of copying it from my older project) so there may be some little mistakes (like that url could be without https:// at the beginning etc, but the concept should work)
    :
    : Hope this helps..
    :
    : [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]
    :
    : [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]

    ----------------------------------------------------------------------

    Hi PavlinII and everyone else,

    What would be needed to simply gain access to a server system
    please?
    Would this seem pointless without downloading file(s)?

    I was looking at System.Net.NetworkAccess

    I would just want to pass my username and password to a uri (url)


    Regards,

    Dr M.


  • : : : : hi,
    : : : :
    : : : : i am new to this board so excuse me if my english is not so good.
    : : : : i have an assignment to write a program
    : : : : that can download file from https protocol.
    : : : : the problem is how can i pass the username and password?
    : : : : thanks.
    : : :
    : : : ======================================================================
    : : : Hi,
    : : :
    : : : I tried the following too and it didn't work. :-(
    : : : [code]
    : : : Public Sub test()
    : : : Dim startInfo As New ProcessStartInfo("IExplore.exe")
    : : : 'startInfo.WindowStyle = ProcessWindowStyle.Minimized
    : : :
    : : : Process.Start(startInfo)
    : : :
    : : : startInfo.Arguments = ("http://outranet.scm.tees.ac.uk/pfp/")
    : : :
    : : : Process.Start(startInfo)
    : : : SendKeys.Send("myUserName" + "{Enter}")
    : : : SendKeys.Send("myPassWord" + "{Enter}")
    : : :
    : : : End Sub
    : : :
    : : : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    : : : test()
    : : : End Sub
    : : : [/code]
    : : :
    : : : Anyone any ideas please?
    : : :
    : : :
    : : : Regards,
    : : :
    : : : Dr M.
    : : :
    : : :
    : : Hi folks,
    : : this would take a little more work.
    : :
    : : [code] [green]'1st - you'll need System.Net.WebClient to download file
    : : [/green]
    : : Dim wc As New Net.WebClient
    : : [green]2nd - you're supposed to decide whether you belive remote ssl certificate, let's blindly say we do :)
    : : [/green]
    : : Dim CredCache As New Net.CredentialCache
    : : [green]3rd - authenticate with login and password. This is example for Digest algorithm in domain. Ask msdn for further details.[/green]
    : : CredCache.Add(New Uri("https://asdf.com"), "Digest", New Net.NetworkCredential("YourLoginName", "YourPassword", "DomainName"))
    : : wc.Credentials = CredCache
    : : [green]4th - download the file and what ever else..[/green]
    : : wc.DownloadFile("https://url.com/file.ext", "c:somewhere.ext")
    : : [/code]
    : : [RED]BUD[/RED] there's a little difference between .NET 1.1 and .NET 2.0 in part "2nd".
    : : In .NET 2.0 (that I used for origin of this code), you do not have to care about validity of SSL certificate, there's a method delegate that you should set to addressof your method which could verify the certificate. If you do not this, the certificate is (blindly) supposed to be correct.
    : : In .NET 1.1, you have to create class implementing ICertificatePolicy interface and it's CheckValidationResult method to decide, if the certificate is fake or not..
    : : [code]
    : : Public Class CertificateValidator
    : : Implements Net.ICertificatePolicy
    : :
    : : Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
    : : Return True [green]'Do I care? For this example I do not. But if there would be my money or privaci in bet, I definitelly WOULD![/green]
    : : End Function
    : : End Class[/code]
    : : You also have to set CertificatePolicy to your class (before downloading that file) like this
    : : [code]ServicePointManager.CertificatePolicy = New CertificateValidator()[/code]
    : :
    : : I didn't test this code as is (because of copying it from my older project) so there may be some little mistakes (like that url could be without https:// at the beginning etc, but the concept should work)
    : :
    : : Hope this helps..
    : :
    : : [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]
    : :
    : : [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]
    :
    : ----------------------------------------------------------------------
    :
    : Hi PavlinII and everyone else,
    :
    : What would be needed to simply gain access to a server system
    : please?
    : Would this seem pointless without downloading file(s)?
    :
    : I was looking at System.Net.NetworkAccess
    :
    : I would just want to pass my username and password to a uri (url)
    :
    :
    : Regards,
    :
    : Dr M.
    :
    :
    :
    Hi,
    I'm not sure what are you asking for..
    What exactly do you need?

    Working with Credentials property is common technique to get access to SSL-secured site.. (When connecting to url by webclient, or web service, for example)
    When you're using WebClient object, you're not forced just do download files from remote server. You can use other methods to explore the remote site (.DownloadData for HTTP GET, .UploadData for HTTP POST, .UploadFile..etc)

    Another way (when you use WinForms) of accessing remote site is using WebBrowser object. After .Navigate method (over HTTPS) should appear standard Yes-No server certificate dialog (2nd part of my previous code), and then UserName/Password dialog (3rd part). User of your app is forced to enter his credentials manually. I'm not sure if there's an alternative way how to automatize this.. (I didn't found Credentials property on WebControl, but I'm sure that the whole process will be simmilar).

    System.Net.NetworkAccess is just enumeration for defining network access permission (with cooperation of WebPermission or SocketPermission) for your application (or assembly) declaring whether your app can access TCP/IP (or other networks) or not.



    [blue][b][italic][size=4]P[/size]avlin [size=4]II[/italic][/size][/b][/blue]

    [purple]Don't take life too seriously anyway you won't escape alive from it![/purple]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories