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: Intermediate:
why the "get" does not bring

 



zafar
New User

May 15, 2011, 10:26 AM

Post #1 of 6 (2603 views)
why the "get" does not bring Can't Post


Code
 # htdocs URL accessibility 
my $res = $ua->get("$f->{srv_htdocs_url}/index.html");
push @tests, $res->content eq 'XFS' ? 'htdocs URL accessibility: OK' : "htdocs URL accessibility: ERROR (should see XFS on <a href='$f->{srv_htdocs_url}/index.html' target=_blank>link</a>)";


I could not understand why the "eq"does not work and why the "get" does not bring the page content correctly.



Code
 # htdocs URL accessibility 
my $res = $ua->get("$f->{srv_htdocs_url}/index.html");
push @tests, $res->content eq 'XFS' ? 'htdocs URL accessibility: OK' : "htdocs URL accessibility: ERROR (should see XFS on <a href='$f->{srv_htdocs_url}/index.html' target=_blank>link</a>) {$res->content}";


Checking the value returned by the variable {$ res-> content} "was" {HTTP:: Response = HASH (0x122c810) -> content} "but the page only has the text" XFS ".


(This post was edited by zafar on May 16, 2011, 4:29 AM)


Zhris
Enthusiast

May 16, 2011, 6:07 AM

Post #2 of 6 (2582 views)
Re: [zafar] why the "get" does not bring [In reply to] Can't Post

Hi,

Firstly, its best to assign the complete url to a seperate variable, otherwise Perl can have difficulty figuring out what is meant to be interpolated and what isn't in a string.


Code
my $url = $f->{srv_htdocs_url} . '/index.html'; 
my $res = $ua->get($url);


This will possibly solve your issues.

Chris


(This post was edited by Zhris on May 16, 2011, 6:24 AM)


FishMonger
Veteran / Moderator

May 16, 2011, 7:39 AM

Post #3 of 6 (2573 views)
Re: [Zhris] why the "get" does not bring [In reply to] Can't Post

Chris,

Perl would not have any problem interpolating that string.

----

zafar,

Did you check the status/value of $res->is_success?

When you said:

Quote
"but the page only has the text" XFS "

Did you mean the rendered page or the source code of the page?

I would expect it to be more like:

Code
<html> 
<head></head>
<body>XFS</body>
</html>


If it is just the 3 letters and not actual html coding, are you sure that it doesn't include and spaces? Have you tried using Data::Dumper to see what it shows is in $res->content?


zafar
New User

May 16, 2011, 8:58 AM

Post #4 of 6 (2568 views)
Re: [FishMonger] why the "get" does not bring [In reply to] Can't Post

 


Quote

Did you check the status/value of $res->is_success?


Returned value: "HTTP::Response=HASH(0x122c740)->is_success"




Quote
When you said:
Quote
"but the page only has the text" XFS "
Did you mean the rendered page or the source code of the page?

I would expect it to be more like:
Code


The source code of the page is just "XFS" no HTML tags.


Quote
my $res = $ua->get("$f->{srv_htdocs_url}/index.html");
use Data::Dumper;
print Dumper($res->content);
push @tests, $res->content eq 'XFS' ? 'htdocs URL accessibility: OK' : "htdocs URL accessibility: ERROR (should see XFS on <a href='$f->{srv_htdocs_url}/index.html' target=_blank>link</a>) {}";


Data::Dumper caused error "500 Internal Server Error"


FishMonger
Veteran / Moderator

May 16, 2011, 9:27 AM

Post #5 of 6 (2566 views)
Re: [zafar] why the "get" does not bring [In reply to] Can't Post

It wasn't clear from your original post that you were running this script in a cgi environment.


Quote
Data::Dumper caused error "500 Internal Server Error"

That's because you didn't output the html header prior to dumping the var.

Try this:

Code
use CGI qw(:standard); 
use Data::Dumper;

my $res = $ua->get("$f->{srv_htdocs_url}/index.html");

print header(), start_html(), pre( Dumper($res->content) );

push @tests, $res->content =~ /XFS/ ? 'htdocs URL accessibility: OK'
: "htdocs URL accessibility: ERROR (should see XFS on <a href='$f->{srv_htdocs_url}/index.html' target=_blank>link</a>) {}";



zafar
New User

May 16, 2011, 11:52 AM

Post #6 of 6 (2559 views)
Re: [FishMonger] why the "get" does not bring [In reply to] Can't Post


Code
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
</head>
<body>
<pre>$VAR1 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /files/index.html could not be found on this server.</p>

<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
';
</pre>Set-Cookie: xfss=wisfmdjbn5pw9x8m; path=/
Date: Mon, 16 May 2011 18:40:10 GMT
Content-Type: text/html; charset=utf-8

It appeared.


Quote
It wasn't clear from your original post that you were running this script in a cgi environment.

In a paid host. (php, cgi, perl ....)

 
 


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

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