Question Problem with login to website

Bauhaus

Member
Joined
May 11, 2008
Messages
12
Programming Experience
Beginner
I'm making a winform program to automatically login to a website and then do a search on the site.
Problem is, it works for one site but not for another.

Here's the code:

VB.NET:
Dim cookies As CookieContainer = New CookieContainer

Try
'   1) Dim request As HttpWebRequest = HttpWebRequest.Create(http://cinemageddon.org/takelogin.php?username=user&password=psw)
'   2) Dim request As HttpWebRequest = HttpWebRequest.Create(http://karagarga.net/takelogin.php?username=user&password=psw)
request.Credentials = CredentialCache.DefaultCredentials
request.CookieContainer = cookies
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Dim dataStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
reader.Close()
response.Close()
Catch ex As Exception
MessageBox.Show("ReadHTML1 Error!")
End Try

Try
'   1) Dim reqTorrent As HttpWebRequest = HttpWebRequest.Create("http://cinemageddon.org/details.php?id=18495&hit=1")
'   2) Dim reqTorrent As HttpWebRequest = httpWebRequest.Create("http://karagarga.net/details.php?id=79711")
reqTorrent.Credentials = CredentialCache.DefaultCredentials
reqTorrent.CookieContainer = cookies
Dim resTorrent As HttpWebResponse = CType(reqTorrent.GetResponse(), HttpWebResponse)
Dim torrentStream As Stream = resTorrent.GetResponseStream()
Dim readTorrent As New StreamReader(torrentStream)
Dim resTorrentFromServer As String = readTorrent.ReadToEnd()
Using anMessageList As New MessageList()
anMessageList.RichTextBoxMessage.Text() = resTorrentFromServer
anMessageList.ShowDialog()
End Using
readTorrent.Close()
resTorrent.Close()
Catch ex As Exception
MessageBox.Show("ReadHTML2 Error!")
End Try
This works perfect for the first site (cinemageddon), but when I try it for the second site (karagarga), Im redirected to the login page.
And they have the same form code:

HTML:
<form method="post" action="takelogin.php">
<table border="0" cellpadding=5>
<tr><td class=rowhead>Username:</td><td align=left><input type="text" size=40 name="username" /></td></tr>
<tr><td class=rowhead>Password:</td><td align=left><input type="password" size=40 name="password" /></td></tr>
<!--<tr><td class=rowhead>Duration:</td><td align=left><input type=checkbox name=logout value='yes' checked>Log me out after 15 minutes inactivity</td></tr>-->
<tr><td colspan="2" align="center"><input type="submit" value="Log in!" class=btn></td></tr>
</table>
</form>

So why does my code work for site 1 but not for site 2 ?
 
I solved the problem by including www in the second url.
Dont know though why the first url doesnt need the www. Also, when I paste the full url without the www in the browser, it works fine.

Any thoughts about that ?
 
Back
Top