gshine has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple code snippet - I am trying to get a WEB page simply to see if it exists - I have tried two separate URL's both of which exist but one returns a uccess code and the second does not. The ebay URL returns success but the therealreal one fail to return a success code. Any help greatly appreciated.
#!/usr/bin/perl use strict; use warnings; use 5.010; use HTTP::Tiny; use LWP::Simple; #This works fine and I get a success response. my $response; $response = HTTP::Tiny->new->get('https://www.ebay.com/itm/13293468937 +0?_trkparms=ispr%3D5&hash=item1ef386625a:g:9aMAAOSwlelcABTQ&amdata=en +c%3AAQAGAAACcPYe5NmHp %252B2JMhMi7yxGiTJkPrKr5t53CooMSQt2orsSHYXPhGXR5uguexJBeHwfgdJ6J58eVuy +chanjrBuo1JP9tlne3ze02hlK%252FFjf05PjtJOLG7lDM%252BxKs%252FjTmZdZ1gyD +gGyRuF45RehkLs7KuyfC %252B3pAeXVl67sjSxlBP0lLY0PHss4j4iGBGRRzexBnH0dJvoIpRkvSe2QChdnf70KZuX +pwlXfeHKeGwiahkPdSbtK38Nw5TolA4S%252BhVaW%252B%252BSa3ZEHC69mI3zuuznY +h9xul0wSdTOQ7COk1j30Nh3M8j3IkCdPYVopDo47ntq4GAn1A %252FnDXrGvvuJW2QEs4MC5%252FeeBSrHNLdzYgczgW1ZdmwkAKpF0NgmaTZKAcBigLXf +5Nw0T0KZHMgTQ44Fs0fKZ9zD2Q4%252BV1OwjQmM8n%252FLINdJR3wm1OQNOVtZdmH5B +MZPiGDM%252BXvQ0ViSvkFoaMQNjcfMbuyL12QV9IMxlLzejVeHznR5ZLxw19dhNiORLo %252FhFGZni5I0xs3WBJNiyg%252BnDwKEj0R9s8JQI1Zqo2VUjUBUCUFMDOUNpS%252Bq +4a5HSPcaPLeOLVnFm%252BiKZWrbmywfE%252Fan6q64guXwhIUP6GT7oq6qDoTOiPF2e +BtLwcN7G5OeR92H0WNfSkLlDm1ux2XETIB9risdL6I %252FXgDmX55FGDq5QxPGnd2tqbrjVhQR5IXo3YpmZ%252BESpbua3iSjzwLCs0Me%252B +512T%252B%252FJ2ebRb2fR8tWhB5EKfM4iNBfDVZbyqLFy7bCnRN2xgC0v27k5Ybntj9 +YoSr9iybiJRATe8INE4nusY%252FiPxtPYBSoRTzQvMiuA%253D%253D%7Cclp%3A2334 +524%7Ctkp %3ABlBMUMjO5uSiXw'); if ($response->{success}) { print 'Success ebay url Length: ', length $response->{content}, " +\n\n"; } else {print 'Failed!!\n'} #This fails and I get a failed response?? $response = get('https://www.therealreal.com/products/women/clothing/j +ackets/chanel-vintage-1991-evening-jacket-bjjd4'); if ($response->{success}) { print 'Success Length: ', length $response->{content}; } else {print 'Failed therealreal.com url !!\n'} exit;

Replies are listed 'Best First'.
Re: HTTP:Tiny issue.
by haukex (Archbishop) on Nov 17, 2021 at 13:29 UTC

    Please use <code> tags to format your code and sample data! And you can omit the giant long ebay URL and replace it with some testing URL like http://www.perlmonks.com.

    use HTTP::Tiny; use LWP::Simple; my $response; $response = HTTP::Tiny->new->get('...') ... $response = get('...');

    For the first request, you're creating a new HTTP::Tiny object and calling the ->get method on it. For the second request, you're using the get function from LWP::Simple, which is quite different. What you want is:

    use HTTP::Tiny; my $http = HTTP::Tiny->new; my $response = $http->get('...'); ... $response = $http->get('...');

    (Tested on URLs different from the OP.)

Re: HTTP:Tiny issue.
by Fletch (Bishop) on Nov 17, 2021 at 13:46 UTC

    Not directly relevant to your module problem but: depending on your use case a HEAD request might be more appropriate than a GET if your sole objective is to test if the URL would return something.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: HTTP:Tiny issue.
by perlfan (Parson) on Nov 17, 2021 at 18:47 UTC
    Can you post more about what you're doing? I can tell you that eBay moving to more JS generated DOMs, so generally speaking you can't rely on content from a direct request. HTML::Tiny will give you the same info as curl or some other utlitiy, so if in doubt check that output.

    Also, for eBay, you can get away with https://www.ebay.com/itm/$itemnum and don't need all that other garbage.

    (update) Another thing to note is if you request an item that doesn't exist (any more), eBay redirects you rather than sending you just a 404.

Re: HTTP:Tiny issue.
by hippo (Archbishop) on Nov 18, 2021 at 00:09 UTC
    but the therealreal one fail to return a success code.

    It returns a 403 indicating that the access is forbidden. That's a perfectly valid thing to happen on the web.


    🦛

Re: HTTP:Tiny issue.
by ikegami (Patriarch) on Nov 17, 2021 at 21:09 UTC

    Fails how? "It doesn't work" is not an acceptable description of the problem

    And contrary to what you said, the first fails too. That's no surprise given the invalid URL you provided. URLs can't contain space and line feeds.