perl - HTTP::Tiny 로 http POST request 날리기. form 데이터 사용
perl - HTTP::Tiny 로 http POST request 날리기. json 데이터 사용
perl - HTTP::Tiny 로 http GET request 날리기 GET 요청 날리기 GET 요청 날리기 - parameter 추가 GET 요청 날리기 - header 추가 POST 요청은 다음에... 참고 HTTP::Tiny http://search.cpan.org/~dagolden/HT..
junho85.pe.kr
지난 글에서는 HTTP::Tiny POST 요청에 json 바디를 넣어서 요청을 했었는데요.
이번에는 form형태의 데이터를 POST 요청을 날리는 방법을 알아보겠습니다. HTTP::Tiny에는 그냥 post요청 외에 post_form함수를 통해 form형태의 데이터를 쉽게 보낼 수 있는 기능을 제공하고 있습니다.
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Data::Dumper;
use HTTP::Tiny;
my $http = HTTP::Tiny->new();
my %headers = ();
my %data = (
name => "junho85",
address => "korea"
);
my $url = "http://httpbin.org/post";
my $response = $http->post_form($url, \%data, {
headers => \%headers,
content => "test content"
});
print $response->{content};
httpbin으로 요청을 보내면 요청했던 정보를 정리해서 응답으로 되돌려 줍니다.
{
"args": {},
"data": "",
"files": {},
"form": {
"address": "korea",
"name": "junho85"
},
"headers": {
"Content-Length": "26",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "HTTP-Tiny/0.076",
"X-Amzn-Trace-Id": "Root=1-608c18e8-209c524543ad97927cae31b5"
},
"json": null,
"origin": "220.78.85.67",
"url": "http://httpbin.org/post"
}
Content-Type이 "application/x-www-form-urlencoded"로 설정되었음을 확인할 수 있습니다.
참고
HTTP::Tiny - A small, simple, correct HTTP/1.1 client - metacpan.org
NAME HTTP::Tiny - A small, simple, correct HTTP/1.1 client VERSION version 0.076 SYNOPSIS use HTTP::Tiny; my $response = HTTP::Tiny->new->get('http://example.com/'); die "Failed!\n" unless $response->{success}; print "$response->{status} $response->{reason
metacpan.org