Click here to Skip to main content
15,909,332 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello!

I would like to make a program which automatically reboots the router if it disconenct from the internet.

Now, it navigates to the right site, but there's a button called Reboot.

properties:

input type="submit" class="buttonText" value="Reboot" style="cursor:hand"

What I can't do is pressing that button by webrequest. What I've done already:
WebRequest myReq = WebRequest.Create("http://192.168.1.254/GBreboot.htm");
            string username = "name";
            string password = "pw";
            string usernamePassword = username + ":" + password;
            CredentialCache mycache = new CredentialCache();
            mycache.Add(new Uri("http://192.168.1.254/GBreboot.htm"), "Basic", new NetworkCredential(username, password));
            myReq.Credentials = mycache;
            myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));

            WebResponse wr = myReq.GetResponse();
            Stream receiveStream = wr.GetResponseStream();
            WebResponse response = (WebResponse)myReq.GetResponse();
            StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
            string resphtml = reader.ReadToEnd();


Any ideas?
Posted

 
Share this answer
 
Comments
velvet7 20-Dec-10 10:35am    
Thanks for the answer! Tried myReq.Method = "REBOOT" (this is what they write), but it gives an error:The remote server returned an error: (501) Not Implemented.
You can try to find out what request is being sent by the browser when you actually press the button yourself. Use a tool like Fiddler2[^] for that.
Then in the first step you do what you did in your existing code to setup an authenticated session. The second step would be to send a request like the one you traced with Fiddler but useing the session information from the first step (session cookies or whatever).

Hope this helps!

Regards,

Manfred
 
Share this answer
 
Comments
velvet7 20-Dec-10 10:44am    
Yea, thanks. Worked pretty well, I just had to go to /man.cgi?redirect=GBstart.htm%3Fsec%3D30&failure=fail.htm&type=reboot
(which Fiddler2 write) But I still would like to know how to click on a button:) But that was the main question!
fjdiewornncalwe 20-Dec-10 11:12am    
Great answer, Manfred. Tschuess...
Manfred Rudolf Bihy 20-Dec-10 12:24pm    
@Marcus: Thanks!
@Velvet7: Nice that it works now. Is that clickety thing still some requirement or now just out of curiosity?
velvet7 20-Dec-10 15:27pm    
Well, I'm still interested in that thing, so if you can find out a solution for it that would be nice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900