PerlでPOSTメソッドの送信を行う

Perl Add comments

PerlでPOSTする必要があったので調べてみた。
HTTP::Request::CommonでPOSTするデータを用意して、LWP::UserAgentに委ねるだけ。
この連携はいつ使っても感動しますね。

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

# POST準備
my $url = 'http://exsample.com/receive.cgi';
my %postdata = ( 'id' => 'id', 'pass' => 'pass' );
my $request = POST( $url, \%postdata );

# 送信
my $ua = LWP::UserAgent -> new;
my $res = $ua -> request( $request ) -> as_string;

One Response to “PerlでPOSTメソッドの送信を行う”

  1. 山田 Says:

    同一サイトでhttpsからhttpへpostした経験はありますか。
    使えると思いためしたら、httpsのファイルを探して
    実行できませんでした。
    この方法では、使えないのでしょうか

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS ログイン