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.
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,
does nothing, because it does. It calls this,
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
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:
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 Using webclient = New CookieAwareWebClient() ' I am going to use a CookieAwareWebClient named webclient Dim values = New NameValueCollection From { _ ' I am starting a NameValueCollection with 2 values {"ctl00_contentPlaceHolder_txtUserName", "username"}, _ ' value 1 {"ctl00_contentPlaceHolder_txtPassword", "password"} _ ' value 2 } ' This is my username and password I will be using later 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 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 Dim doc As New HtmlDocument ' This is an HTMLAgilityPack document doc.LoadHtml(html) ' I am loading the document with my dream-based page I wish to access webclient.DownloadString("logoutURL") ' I am now logging out and unlocking the page I previously accessed webclient.Dispose() ' Disposing of the evidence Return doc ' I am returning dream-based HTML document that I wish I could access End Using 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)Code:
Protected Overrides Function GetWebRequest(address As Uri) As WebRequest
Dim request = DirectCast(MyBase.GetWebRequest(address), HttpWebRequest)
request.CookieContainer = CookieContainer
Return request
End FunctionThe 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