Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27513

VS 2012 What Am I missing, WebClient

$
0
0
Can somebody tell me what step I am missing here, a code example please, not a vague description such as "you need to check the force of the pie hitting the tree, then calculate how far the debris will travel with a 43mph up-wind, all while eating a hamburger full of broken light bulbs".

I am trying to simply LOG INTO a website using a CookieAwareWebClient, basically a WebClient that accepts/generates cookies. This is supposed to be a very, extremely, simple task. It is not however, I have gotten about 4 responses on the matter that were not of use to me, they may have been close but did not help, I will explain step by step what I am doing so maybe, somebody can give me some helpful advice, or just throw an answer at me worth reading.

vb .net Code:
  1. Public Function GetPage(ByVal url As String) As HtmlDocument ' this is me declaring the function to Get a Page, by a URL that is named in another sub
  2.         Using webclient = New CookieAwareWebClient() ' I am going to use a CookieAwareWebClient named webclient
  3.             Dim values = New NameValueCollection From { _   ' I am starting a NameValueCollection with 2 values
  4.              {"ctl00_contentPlaceHolder_txtUserName", "username"}, _   ' value 1
  5.              {"ctl00_contentPlaceHolder_txtPassword", "password"} _   ' value 2
  6.             }    ' This is my username and password I will be using later
  7.             webclient.UploadValues("loginURL", values)  ' Here is where I upload the information ( I am calling a POST, with automatically generated cookies ), with the values previously stated
  8.  
  9.             Dim html As String = webclient.DownloadString(url)   ' I am now using the URL named from another sub, to get to the page I can only dream of accessing via WebClient
  10.             Dim doc As New HtmlDocument  ' This is an HTMLAgilityPack document
  11.             doc.LoadHtml(html)  ' I am loading the document with my dream-based page I wish to access
  12.             webclient.DownloadString("logoutURL")  ' I am now logging out and unlocking the page I previously accessed
  13.             webclient.Dispose()  ' Disposing of the evidence
  14.             Return doc  ' I am returning dream-based HTML document that I wish I could access
  15.         End Using
  16.     End Function

What is missing here? VB gods please guide me for I am worthy, as a servant, and follower.

Can I please have a code example of what I am missing with a half-decent explanation.


Do not say that this,
Code:

webclient.UploadValues("loginURL", values)
does nothing, because it does. It calls this,
Code:

    Protected Overrides Function GetWebRequest(address As Uri) As WebRequest
        Dim request = DirectCast(MyBase.GetWebRequest(address), HttpWebRequest)
        request.CookieContainer = CookieContainer
        Return request
    End Function

which is working completely as intended.

The problem is in that line though, however, as the credentials I am trying to pass through are not working, I am not accessing the username/password fields correctly I do not think, this is where I need assistance

Viewing all articles
Browse latest Browse all 27513

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>