Hallo ich habe folgendes Problem ich würde gerne alle 12Std meinen Router neustarten aber es scheitert schon am Login.
Habe diesen Thread gefunden: [VB.NET] Router-Login via HttpWebRequest aber irgendwie will das nicht so ganz.
Diesen Fehler bekomme ich dauernd
Spoiler anzeigen
Mein Sourcecode:
HTTP header:
Spoiler anzeigen
Mfg Flo
Habe diesen Thread gefunden: [VB.NET] Router-Login via HttpWebRequest aber irgendwie will das nicht so ganz.
Diesen Fehler bekomme ich dauernd
System.Net.WebException wurde nicht behandelt.
Message=The remote server returned an error: (404) Not Found.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at ConsoleApplication1.Module1.DoRequest(String url, String password, CookieContainer container) in C:\Users\Flo\AppData\Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 39
at ConsoleApplication1.Module1.Main() in C:\Users\Flo\AppData\Local\Temporary Projects\ConsoleApplication1\Module1.vb:line 10
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Mein Sourcecode:
VB.NET-Quellcode
- Imports System.Net
- Imports System.Text
- Imports System.IO
- Module Module1
- Public Sub Main()
- Dim sURL As String = "https://speedport.ip/cgi-bin/login.cgi"
- Dim sPw As String = "12345678"
- Dim cContainer As CookieContainer
- Console.WriteLine(DoRequest(sURL, sPw, cContainer))
- Dim input As String = Console.ReadLine()
- End Sub
- Public Function DoRequest(ByVal url As String, ByVal password As String, ByVal container As CookieContainer) As String
- Dim reqLogin As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://speedport.ip/cgi-bin/login.cgi"), HttpWebRequest)
- reqLogin.CookieContainer = container
- reqLogin.Method = "POST"
- reqLogin.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0"
- reqLogin.Referer = "https://speedport.ip/html/login/"
- reqLogin.KeepAlive = True
- reqLogin.Host = "speedport.ip"
- reqLogin.ContentType = "application/x-www-form-urlencoded"
- reqLogin.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- reqLogin.Headers.Add("Accept-Language", "de-de,de;q=0.8,en-us;q=0.5,en;q=0.3")
- reqLogin.Headers.Add("Accept-Encoding", "gzip, deflate")
- Dim encoding As New ASCIIEncoding()
- Dim data As String = Uri.EscapeDataString("password") & "=" & Uri.EscapeDataString(password)
- Dim bytes As Byte() = encoding.GetBytes(data)
- reqLogin.ContentLength = bytes.Length
- Dim stream As Stream = reqLogin.GetRequestStream
- stream.Write(bytes, 0, bytes.Length)
- stream.Close()
- Dim resLogin As HttpWebResponse = DirectCast(reqLogin.GetResponse(), HttpWebResponse)
- Dim CookieHeaderValue As String = reqLogin.Headers.Get("Cookie")
- If CookieHeaderValue <> Nothing Then
- Dim aCookie As String() = CookieHeaderValue.Split("=")
- Dim Cookie As New Cookie
- Cookie.Domain = "speedport.ip"
- Cookie.Path = "/"
- Cookie.Secure = True
- Cookie.Name = aCookie(0)
- Cookie.Value = aCookie(1)
- container.Add(Cookie)
- End If
- Dim reqIndex As HttpWebRequest = DirectCast(HttpWebRequest.Create(url), HttpWebRequest)
- reqIndex.CookieContainer = container
- reqIndex.Method = "GET"
- reqIndex.Referer = "https://speedport.ip/wait_login.stm"
- reqIndex.KeepAlive = True
- reqIndex.Host = "speedport.ip"
- reqIndex.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
- Dim resIndex As HttpWebResponse = DirectCast(reqIndex.GetResponse(), HttpWebResponse)
- Dim sr As StreamReader = New StreamReader(resIndex.GetResponseStream())
- Dim output As String = sr.ReadToEnd
- resIndex.Close()
- Return output
- End Function
- End Module
HTTP header:
speedport.ip/data/Login.json
POST /data/Login.json HTTP/1.1
Host: speedport.ip
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: application/json, text/javascript, */*
Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: speedport.ip/html/login/
Content-Length: 26
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
password=12345678&showpw=0
HTTP/1.1 200 OK
Date: Thu, 13 Feb 2014 14:55:35 GMT;
Server: Apache
Pragma: no-cache, no-cache
Cache-Control: max-age=0, must-revalidate, no-cache
Set-Cookie: aDuPtHhDTW921Vcb4b66f=ETOd2eCSmJiWlhGdG3W96m_LFp_JSn5siKcnyIlAzby7xalSkFYc; Path=/; Secure; expires=Thu, 13 Feb 2014 15:05:35 GMT;
Connection: Keep-Alive
Content-Type: application/javascript
Expires: -1
Mfg Flo