sergot / http-useragent

Web user agent class for Perl 6.
MIT License
36 stars 39 forks source link

How does the `.post` method work? #247

Closed swaggboi closed 9 months ago

swaggboi commented 9 months ago

I am trying to make a simple request using the .post method like so:

#!/usr/bin/env raku

use v6.d;
use HTTP::UserAgent;

my $uri      = 'https://hyperlink-redirect.seriousbusiness.international/';
my $ua       = HTTP::UserAgent.new;
my %form     = hyperlink => 'example.com';
my $bin      = False;
my %header   = X-Cool-Request => 'Heck';
my $response = $ua.post($uri, %form, :$bin, %header);

say $response.status-line;

When I run this I get the following like it doesn't like the subroutine signatures:

Cannot resolve caller post(HTTP::UserAgent:D: Str:D, Hash:D, Hash:D, :!bin); none of these signatures matches:
    (HTTP::UserAgent: URI $uri is copy, %form, Bool :$bin, *%header)
    (HTTP::UserAgent: Str $uri is copy, %form, Bool :$bin, *%header)
  in block <unit> at make-request.raku line 13

Am I doing this wrong? I tried searching but all the prior issues I see are from before it seems the .post method was implemented?

swaggboi commented 9 months ago

Disregard, I got it working by just passing the header as a pair rather than a hash:

#!/usr/bin/env raku

use v6.d;
use HTTP::UserAgent;

my $uri      = 'https://hyperlink-redirect.seriousbusiness.international/';
my $ua       = HTTP::UserAgent.new;
my %form     = hyperlink => 'example.com';
my $bin      = False;
my $response = $ua.post: $uri, %form, :$bin, X-Cool-Request => 'Heck';

say $response.status-line;

This returns a 200 as expected.