CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
HTTP::Tiny question

 



planejanez
New User

Jul 22, 2016, 10:38 AM

Post #1 of 7 (2794 views)
HTTP::Tiny question Can't Post

I'm currently using OpenBSD and curl and wget aren't part of the OpenBSD base so I would rather attempt to reboot my cable modem (SB6183) using perl HTTP:Tiny if possible. The following 2 commands work and both will reboot my modem:


Code
curl -d Rebooting=1 http://192.168.100.1/goform/RgConfiguration 

wget --post-data=Rebooting=1 http://192.168.100.1/goform/RgConfiguration


Below is something I came up with that doesn't work. I need to implement post data Rebooting=1 for it to work but I can't figure that out:


Code
perl -MHTTP::Tiny -E 'say HTTP::Tiny->new->post("http://192.168.100.1/goform/RgConfiguration")


Anyone have any ideas on proper HTTP::Tiny syntax so this will work? The HTTP:Tiny code snippet above is a one liner attempt. Instead of a one liner a perl script would do. If someone has the time it would be great to see a simple perl script I could use to reboot my cable modem.

If you notice on the screenshot configuration page that's attached to this post there is a reboot button. When the button is pressed a popup windows appears asking "Are you sure you want to reset the modem". I'm attaching the screenshot of the modem configuration page, a screenshot of the popup window that appears after selecting reboot and the view source output of the page.

I'm willing to make a paypal donation for your time. Thank you.


(This post was edited by planejanez on Jul 22, 2016, 10:41 AM)
Attachments: modem configuration page.jpg (57.9 KB)
  reboot button pressed.jpg (52.7 KB)
  view source of configuration page.txt (16.2 KB)


FishMonger
Veteran / Moderator

Jul 22, 2016, 2:05 PM

Post #2 of 7 (2786 views)
Re: [planejanez] HTTP::Tiny question [In reply to] Can't Post

I haven't used the module, but you forgot to include the form data in the call.
http://search.cpan.org/~dagolden/HTTP-Tiny-0.058/lib/HTTP/Tiny.pm#post_form


planejanez
New User

Jul 22, 2016, 5:00 PM

Post #3 of 7 (2781 views)
Re: [FishMonger] HTTP::Tiny question [In reply to] Can't Post

Well no solution yet. I've tried post_form and right now I'm working with post. The below code doesn't produce any errors but I'm not passing the Request Body which should be Rebooting=1. Below is the code I currently have. Does anyone know how I can include the Rebooting=1 so I can pass that information as well?


Code
#!/usr/bin/perl 

use strict;
use warnings;

use HTTP::Tiny;
my $url = 'http://192.168.100.1/goform/RgConfiguration';
my $header = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => '11'};


HTTP::Tiny->new->post($url, $header);



FishMonger
Veteran / Moderator

Jul 22, 2016, 5:14 PM

Post #4 of 7 (2778 views)
Re: [planejanez] HTTP::Tiny question [In reply to] Can't Post

What does your post_form test code look like?


planejanez
New User

Jul 22, 2016, 7:23 PM

Post #5 of 7 (2774 views)
Re: [FishMonger] HTTP::Tiny question [In reply to] Can't Post

Very similar mainly because I don't know how to handle the $form_data, \%options portion of the port_form function.


Code
post_form 

$response = $http->post_form($url, $form_data);
$response = $http->post_form($url, $form_data, \%options);


I sure the $url portion in my case would be 'http://192.168.100.1/goform/RgConfiguration'.

At this point I'm stuck and I'm just looking around the internet for more information and possible more help on the forum here. I'll report back if I find a solution.


FishMonger
Veteran / Moderator

Jul 23, 2016, 6:14 AM

Post #6 of 7 (2767 views)
Re: [planejanez] HTTP::Tiny question [In reply to] Can't Post

Try:

Code
#!/usr/bin/perl 

use strict;
use warnings;
use HTTP::Tiny;

my $url = 'http://192.168.100.1/goform/RgConfiguration';
my $form_data = { Rebooting => 1 };
my $http = HTTP::Tiny->new;
my $response = $http->post_form($url, $form_data);

if ( $response->{success} ) {
print "Modem rebooted\n";
}
else {
print "Reboot failed: ", $response->{reason}, "\n";
}



planejanez
New User

Jul 23, 2016, 7:12 AM

Post #7 of 7 (2762 views)
Re: [FishMonger] HTTP::Tiny question [In reply to] Can't Post

FishMonger that works perfect! Thank you!

Here's a working one liner I can use from the OpenBSD command prompt. Again, this is to reboot the Arris SURFboard SB6183 cable modem using the built in Perl HTTP::Tiny module.


Code
perl -MHTTP::Tiny -E 'HTTP::Tiny->new->post_form("http://192.168.100.1/goform/RgConfiguration", { Rebooting => 1 })'



(This post was edited by planejanez on Jul 23, 2016, 2:12 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives