2

Need to send HTTP OPTIONS Request in Perl. Looked through several CPAN modules; read the docs, no mention of OPTIONS request method, just GET, POST, PUT, DELETE.

Do I need to format this manually? Or is there possibly another library/module that my google-fu is missing out on?

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262

1 Answers1

5

The documentation for the HTTP::Request module says:

The method should be a short string like "GET", "HEAD", "PUT" or "POST".

So:

use v5.16;
use warnings;

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

my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new(OPTIONS => 'http://www.example.com/');
my $response = $ua->request($request);

I don't have a server that gives a useful response to an OPTIONS request to test the response with, but the request looks OK when I examine it after setting a proxy.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335