简体   繁体   English

选项Perl中的HTTP请求

[英]OPTIONS HTTP Request in Perl

Need to send HTTP OPTIONS Request in Perl. 需要在Perl中发送HTTP OPTIONS请求。 Looked through several CPAN modules; 浏览了几个CPAN模块; read the docs, no mention of OPTIONS request method, just GET, POST, PUT, DELETE. 阅读文档,没有提到OPTIONS请求方法,只有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? 还是我的Google-fu可能缺少另一个库/模块?

The documentation for the HTTP::Request module says: HTTP::Request模块的文档说:

The method should be a short string like "GET", "HEAD", "PUT" or "POST". 该方法应为短字符串, 例如 “ GET”,“ HEAD”,“ PUT”或“ 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. 我没有服务器对OPTIONS请求提供有用的响应来测试响应,但是在设置代理后检查该请求时,该请求看起来不错。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM