website logins are an easy thing to do. All you have to remember is post all inputs for the form. Also always check for any javascript in the form that might need to be implemented in your code. Once you do that you are good to go. Here is a snippet of the post function.
Private Function WebPost(ByVal URL As String, ByVal PostData As String) As String Try Dim responsedata As String Dim responsereader As IO.StreamReader
webrequest = CType(webrequest.Create(URL), Net.HttpWebRequest) webrequest.Method = "POST" webrequest.UserAgent = "Mozilla/5.001 (windows; U; NT4.0; en-us) Gecko/25250101" webrequest.ContentType = "application/x-www-form-urlencoded" webrequest.CookieContainer = cookies ' write the form values into the request message Dim requestWriter As IO.StreamWriter = New IO.StreamWriter(webrequest.GetRequestStream()) requestWriter.Write(PostData) requestWriter.Close() responsereader = New IO.StreamReader(webrequest.GetResponse().GetResponseStream())
'and read the response responsedata = responsereader.ReadToEnd() responsereader.Close() webrequest.GetResponse().Close() Return responsedata Catch ex As Exception MsgBox(ex.Message) End Try Return "" End Function
239 Responses to Website login through code