need help with HTTP::Request::Common

Discussion in 'Perl Misc' started by Some Guy, Mar 12, 2005.

  1. Some Guy

    Some Guy Guest

    I'm trying to use HTTP::Request::Common, and can't get it to work.
    Specifically, I'm trying to use it on
    http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100 to get
    geocaches by zipcode, using the following:

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

    use strict;
    use warnings;

    use LWP::UserAgent;
    use HTTP::Request::Common;


    my $action = POST 'http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100',
    [
    'DropDownTaxonomy' => '9a79e6ce-3344-409c-bbe9-496530baf758',
    'LocationPanel1:ddSearchType' => 'ZIP',
    'LocationPanel1:OriginText' => '90210'
    ];

    $action->header( 'User-Agent' => 'Mozilla/5.0' );

    my $ua = LWP::UserAgent->new;
    my $request = $ua->request( $action );

    $request->is_success or die $request->status_line;

    my $content = $request->content;


    my $file = "tmp.txt";
    open(FILE, ">$file") or die "Error opening file";
    print FILE $content;
    close(FILE);

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

    I seem to only be getting the
    http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100 page
    returned to me, not the search results page. Any ideas?
     
    Some Guy, Mar 12, 2005
    #1
    1. Advertising

  2. Some Guy

    Guest

    The most likely reason is that you don't have all required fields in
    your post request, such as:

    LocationPanel1:btnLocale
     
    , Mar 12, 2005
    #2
    1. Advertising

  3. Some Guy <> wrote:

    > I'm trying to use HTTP::Request::Common, and can't get it to work.



    Why are you making a POST rather than a GET?


    > http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100 to get

    ^^^^
    ^^^^

    Where is that "asdf" zipcode anyway?


    > my $action = POST 'http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100',



    use LWP::Simple;

    my $zip = '90210';
    my $html = get 'http://www.geocaching.com/seek/nearest.aspx?'
    . "zip=$zip&dist=100";


    Works for me...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 13, 2005
    #3
  4. Tad McClellan wrote:

    > Some Guy <> wrote:
    >
    >
    >
    >> http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100 to get

    > ^^^^
    > ^^^^
    >
    > Where is that "asdf" zipcode anyway?


    Near "xyzzy", I think.


    --
    Christopher Mattern

    "Which one you figure tracked us?"
    "The ugly one, sir."
    "...Could you be more specific?"
     
    Chris Mattern, Mar 13, 2005
    #4
  5. Some Guy

    Some Guy Guest

    Tad McClellan <> wrote in message news:<>...
    > Some Guy <> wrote:
    >
    > > I'm trying to use HTTP::Request::Common, and can't get it to work.

    >
    >
    > Why are you making a POST rather than a GET?
    >
    >
    > > http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100 to get

    > ^^^^
    > ^^^^
    >
    > Where is that "asdf" zipcode anyway?
    >
    >
    > > my $action = POST 'http://www.geocaching.com/seek/nearest.aspx?zip=asdf&dist=100',

    >
    >
    > use LWP::Simple;
    >
    > my $zip = '90210';
    > my $html = get 'http://www.geocaching.com/seek/nearest.aspx?'
    > . "zip=$zip&dist=100";
    >
    >
    > Works for me...


    The thing is, I'm living in Canada, so our zip codes (postal codes)
    are formatted differently, like A1B-2C3. I tried using a get and it
    didn't work, but I just figured out now that if I put a space in the
    postal code where the hyphen is, it accepts it. Thanks for the
    response!
     
    Some Guy, Mar 13, 2005
    #5
  6. Some Guy <> wrote:
    > Tad McClellan <> wrote in message news:<>...
    >> Some Guy <> wrote:
    >>
    >> > I'm trying to use HTTP::Request::Common, and can't get it to work.



    Just to be clear. Your problem had nothing to do with that module.

    (this thread was an XY-problem)


    > The thing is, I'm living in Canada, so our zip codes (postal codes)
    > are formatted differently, like A1B-2C3.



    Then why did you give us 2 examples that were not formatted that way?


    > I just figured out now that if I put a space in the
    > postal code where the hyphen is, it accepts it.



    Just like when you use the search form normally via a browser.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 13, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sure
    Replies:
    1
    Views:
    609
    Jim Gibson
    Sep 2, 2004
  2. Denny
    Replies:
    1
    Views:
    820
  3. Replies:
    9
    Views:
    285
    Charles DeRykus
    Mar 14, 2006
  4. Alex
    Replies:
    1
    Views:
    181
    Gunnar Hjalmarsson
    Mar 20, 2006
  5. Replies:
    1
    Views:
    248
    zentara
    Nov 6, 2006
Loading...

Share This Page