Httpwebrequest with cookies?

bent0

New member
Joined
Oct 27, 2009
Messages
1
Programming Experience
Beginner
Hi there, what's up..
Since a few days I play arround with HTTPwebrequest, it's an easy thing i guess, but there are less tutorials to make it as easy as it is.
I want to make a Login checker. With an Webrequest the tool should login. Then a Streamread3er should search for an Word in the Website source.

That's how far I am:

VB.NET:
Imports System.IO, System.Net, System.Text

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'The Webrequest to the Login Page
        Dim Request As HttpWebRequest = CType(WebRequest.Create("http://login.web.de/"), HttpWebRequest)
        

	'Post the Informations
        Request.Method = "POST"
        Request.ContentType = "application/x-www-form-urlencoded"
        
        Dim Post As String = "username= MYUSERNAME &password= MYPASSWORD &service=kundencenter&server=https%3A%2F%2Fkundencenter.web.de"
       

        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
        Request.ContentLength = byteArray.Length
        Dim DataStream As Stream = Request.GetRequestStream()
        DataStream.Write(byteArray, 0, byteArray.Length)
        DataStream.Close()


	'The Streamreader
        Dim Response As HttpWebResponse = Request.GetResponse()
        DataStream = Response.GetResponseStream()
        Dim reader As New StreamReader(DataStream)
        Dim ServerResponse As String = reader.ReadToEnd()
        reader.Close()
        DataStream.Close()
        Response.Close()

        If InStr(ServerResponse, "codeinthesource") Then
            MessageBox.Show("Login is OK")
        Else
            MessageBox.Show("Login is not OK")
        End If


	'Displays me the Source in a Textbox so I can see what is happened
        TextBox1.Text = ServerResponse

    End Sub
End Class


The Login isn't succesfull, shure I have got a Usrname and Password wich is correct.
I guess I have to use cookies, but how i can do?

Here the HTTPLIVEHEADERS:

https://login.web.de/intern/login/

POST /intern/login/ HTTP/1.1
Host: login.web.de
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: WEB.DE Kundencenter - Login
Cookie: ns_sample=15
Content-Type: application/x-www-form-urlencoded
Content-Length: 95
username= MYUSERNAME &password= MYPASSWIRD &service=kundencenter&server=https%3A%2F%2Fkundencenter.web.de
HTTP/1.x 302 Found
Date: Tue, 27 Oct 2009 17:48:47 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7c mod_copstng/2.4
Content-Type: text/html
Location: https://kundencenter.web.de/intern/...00035AF7C89607FF7332DCC69055779B570C&kill=yes
Pragma: no-cache
Cache-Control: no-cache
Expires: -1
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 224
Connection: close
----------------------------------------------------------
https://kundencenter.web.de/intern/...00035AF7C89607FF7332DCC69055779B570C&kill=yes

GET /intern/jump/?use=&goto=&service=login&si=&session=0000035AF7C89607FF7332DCC69055779B570C&kill=yes HTTP/1.1
Host: kundencenter.web.de
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: WEB.DE Kundencenter - Login
Cookie: JSESSIONID=FA492F7B25DCFBF1FC8C9DB7D2652A7A.a01a02d10t11; ns_sample=15; csc_test_cookie=Tue%2C%2027%20Oct%202009%2017%3A48%3A24%20GMT

HTTP/1.x 302 Moved Temporarily
Date: Tue, 27 Oct 2009 17:48:47 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7d mod_jk/1.2.26
Location: https://kundencenter.web.de/webde/client/index.html
Content-Length: 0
Connection: close
Content-Type: text/plain
----------------------------------------------------------
https://kundencenter.web.de/services/csc/loginname

GET /services/csc/loginname HTTP/1.1
Host: kundencenter.web.de
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: text/plain, */*
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: https://kundencenter.web.de/webde/client/index.html
Cookie: JSESSIONID=FA492F7B25DCFBF1FC8C9DB7D2652A7A.a01a02d10t11; ns_sample=15; csc_test_cookie=Tue%2C%2027%20Oct%202009%2017%3A48%3A24%20GMT

HTTP/1.x 200 OK
Date: Tue, 27 Oct 2009 17:48:47 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.7d mod_jk/1.2.26
Pragma: no-cache
Cache-Control: no-cache, must-revalidate
Expires: -1
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain
----------------------------------------------------------
https://webdessl.ivwbox.de/cgi-bin/ivw/CP/280;?d=50937&r=http://login.web.de/

GET /cgi-bin/ivw/CP/280;?d%3D50937%26r=http%3A//login.web.de/ HTTP/1.1
Host: webdessl.ivwbox.de
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://kundencenter.web.de/webde/client/index.html
Cookie: i00=016a4ae72521ac700005

HTTP/1.x 302 FOUND
Date: Tue, 27 Oct 2009 17:48:48 GMT
Server: srp/2ac
Last-Modified: Tue, 22 Aug 2000 15:05:01 GMT
Pragma: no-cache
Cache-Control: no-cache, must-revalidate
Expires: 0
P3P: policyref=http://p3p.infonline.de/p3p.xml, CP=NOI DSP NID PSAa OUR NOR UNI COM NAV
Location: /blank.gif
Content-Type: text/plain
Connection: close
----------------------------------------------------------
https://pixelbox.uimserv.net/cgi-bi...aN&cona=&cost=?d=32364&r=http://login.web.de/

GET /cgi-bin/webde/CP/280;sc%3Dfreemail/csc/startsitemain%26jsv%3D1.4%26scr%3D1280x1024%26flv%3D10%26vid%3Dnone%26vct%3D15%26res%3Dfreemail/csc/startsitemain%26smv%3DNaN%26cona%3D%26cost%3D?d%3D32364%26r=http%3A//login.web.de/ HTTP/1.1
Host: pixelbox.uimserv.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://kundencenter.web.de/webde/client/index.html
Cookie: NGUserID=d948caa1-1561-1256664633-4; NGHourCount=d948caa1-1561-1256664633-4|fmuser:1.0.0.0:1256664688

HTTP/1.x 200 OK
Date: Tue, 27 Oct 2009 17:48:48 GMT
Server: Apache/2.0.61 (Unix) mod_ssl/2.0.61 OpenSSL/0.9.7l
Set-Cookie: NGUserID=d948caa1-1561-1256664633-4; path=/; domain=.uimserv.net; expires=Wed, 27-Oct-2010 17:48:48 GMT
Last-Modified: Tue, 02 Sep 2008 15:03:29 GMT
Etag: "154017-2a-5c03240"
Accept-Ranges: bytes
Content-Length: 42
Cache-Control: max-age=0
Expires: Tue, 27 Oct 2009 17:48:48 GMT
P3P: policyref="http://adimg.uimserv.net/UIM/netgravity/p3p/p3p.xml", CP="NON DSP NID CURa ADMa DEVa TAIa PSAa PSDa OUR STP BUS UNI COM NAV INT"
Pragma: no-cache
Connection: close
Content-Type: image/gif
----------------------------------------------------------


Well you may saw on my bad speling that I am a German, web.de is a german Mail Service (free) ;) But the same with youtube. How can i use cookies?
 
Back
Top