Link to home
Start Free TrialLog in
Avatar of mmcw
mmcw

asked on

400 URL must be absolute

I am using the following code:

--------------------------------------------------------------------------------
 Code
--------------------------------------------------------------------------------
 
  #!/usr/bin/perl

my $debug_fake_cron = 1;

use LWP;

my $row = "http://www.mmc-shop.nl/cgi-bin/Shop/shop_art.cgi";

print "Content-type: text/html\r\n\r\n" if ($debug_fake_cron);
print "Start execute command: $executable ($row)<br />" if ($debug_fake_cron);
my $browser = LWP::UserAgent->new();
$browser->agent("SmartCron");
$browser->timeout(5);
my $response = $browser->get('$row');

if ($response->is_success) {
      print "Success: " .$response->content . "<br />" if ($debug_fake_cron);
}
else {
      print "Error: " .$response->status_line . "<br />" if ($debug_fake_cron);
}

print "Execute command: $row<br />" if ($debug_fake_cron);
$browser->request(HTTP::Request->new(GET => $row)) or ($error = 1);

exit(0);

--------------------------------------------------------------------------------
 


It will return the following:

--------------------------------------------------------------------------------
 
Start execute command: (http://www.mmc-shop.nl/cgi-bin/Shop/shop_art.cgi)
Error: 400 URL must be absolute
Execute command: http://www.mmc-shop.nl/cgi-bin/Shop/shop_art.cgi

--------------------------------------------------------------------------------
 


However I get the message: 400 URL must be absolute
What does it mean and what am I doing wrong to make this work?
Avatar of Dave Cross
Dave Cross
Flag of United Kingdom of Great Britain and Northern Ireland image

> my $response = $browser->get('$row');

This line isn't doing what you think it is. The single quotes prevent $row from being expanded, so instead of requesting the url which is in $row, you are requesting the literal string '$row' - which (obviously) isn't a well-formed URL.

If you want variables to be expanded in strings then you need to use double quotes, not single quotes.

my $response = $browser->get("$row");

But in this case, there's absolutely no reason at all to use quotes.

my $response = $browser->get($row);

Dave...
Avatar of mmcw
mmcw

ASKER

Untill for short the following code was working!
Now it is stopped?

#!/usr/bin/perl

my $debug_fake_cron = 1;

use LWP;

my $row = "http://www.mmc-shop.nl/cgi-bin/Shop/shop_art.cgi?action=update_correction&use_cron=1";

my $browser = LWP::UserAgent->new();
$browser->agent("SmartCron");
$browser->timeout(5);

$browser->request(HTTP::Request->new(GET => $row));

print "Content-type: text/html\r\n\r\n" if ($debug_fake_cron);
print "Execute command: $row<br />" if ($debug_fake_cron);

exit(0);

What is wrong and how to fix it?
I have no idea what you are expecting the code to do, so I don't know what it has stopped doing :)

You don't seem to be checking the response at all. What unexpected behaviour are you seeing?

Dave...
Avatar of mmcw

ASKER

How to check the response?
ASKER CERTIFIED SOLUTION
Avatar of Dave Cross
Dave Cross
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmcw

ASKER

It looks like it will not except the "?action=update_correction&use_cron=1" part.
Do I have to make some changes therefor?
Avatar of mmcw

ASKER

To explain what I want to do with the script (lets call it script.pl) is that I want to start the URL given ("http://www.mmc-shop.nl/cgi-bin/Shop/shop_art.cgi?action=update_correction&use_cron=1") at the background! But there doesn't have to be a redirection to that URL and the starting script (script.pl) has to be continuet! That was and is my problem from the starting on! The 400 error line was the first problem I can with when I tried to use teh responce option to see what I am doing wrong?

Or am I doing it completely wrong and have to do it another way??
Avatar of mmcw

ASKER

When I try a line as:

print "Location: $row\n\n";

It will start the script given at $row but will redirect to that script and will not return to the main script! Thats my problem. Thats why I made it a difficult (250 points) question!

Avatar of mmcw

ASKER

As a cron command executed on a sertain time and date!
Avatar of mmcw

ASKER

Thank you for your reply!
I did found the solution myself.

The code I asked you to look for wasn't the problem but it was in the script to be executed!