Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
.Net Web Control
Message
De
29/11/2006 10:17:50
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01172849
Message ID:
01173265
Vues:
10
>Thanx for the reply,
>But since i am into VB.net i can not understand C# code can you convert the code in the article into vb.net, also what references must be added in the project for Web Client Class
>
>Regards

Riyaz,

Here is part of the translation to get you started:
Imports System.Net
Imports System.Web

Module Module1

    Sub Main()

        Dim Response As System.Web.HttpResponse

        Dim LOGIN_URL As String = "http://www.msn.com"
        Dim USERNAME As String = "foo@bar.com"
        Dim PASSWORD As String = "hello"

        Dim wc As New WebClient
        Dim rsp As Byte()
        Dim viewstate As String
        Dim postData As String

        rsp = wc.DownloadData(LOGIN_URL)
        viewstate = ExtractViewState(System.Text.Encoding.ASCII.GetString(rsp))
        postData = String.Format( _
            "__VIEWSTATE={0}&UsernameTextBox={1}&PasswordTextBox={2}&LoginButton=Login", _
            viewstate, USERNAME, PASSWORD)

        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        rsp = wc.UploadData(LOGIN_URL, "POST", System.Text.Encoding.ASCII.GetBytes(postData))


    End Sub

    Private Function ExtractViewState(ByVal s As String) As String
        Dim viewStateNameDelimiter As String = "__VIEWSTATE"
        Dim valueDelimiter As String = "value="""
        Dim viewStateNamePosition As Integer = s.IndexOf(viewStateNameDelimiter)
        Dim viewStateValuePosition As Integer = s.IndexOf(valueDelimiter, _
            viewStateNamePosition)

        Dim viewStateStartPosition As Integer = viewStateValuePosition + valueDelimiter.Length
        Dim viewStateEndPosition As Integer = s.IndexOf("""", viewStateStartPosition)

        Return HttpUtility.UrlEncodeUnicode(s.Substring(viewStateStartPosition, _
            viewStateEndPosition - viewStateStartPosition))
    End Function

End Module
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform