# Http Client

```perl
#!/usr/bin/perl
use warnings;
use strict;

use URI::URL;
use HTTP::Headers;
use HTTP::Request;
use LWP::UserAgent;

my $url = new URI::URL('https://www.example.com');
my $headers = new HTTP::Headers(
    'Accept' => 'text/html',
    'User-Agent' => 'Elex/1.0'
);
my $request = new HTTP::Request('GET', $url, $headers);
my $user_agent = new LWP::UserAgent;

my $response = $user_agent->request($request);
if ($response->is_success) {
    print $response->content;
} else {
    print $response->message;
}
```

## LWP::UserAgent

```perl
my $user_agent = new LWP::UserAgent;
```

- request

- credentials

- get_basic_credentials

- timeout


## HTTP::Request

```perl
my $request = new HTTP::Request($method, $url, $headers, $content);
```

- method : GET, POST 등

- url : 문자열 또는 `URI::URL` 객체

- headers : `HTTP::Headers` 객체

- content : 요청 바디


## HTTP::Response

```perl
my $response = $user_agent->request($request);
```

서버 측에서 응답을 생성하려는 경우에는

```perl
my $response = HTTP::Response->new($status_code, $msg, $header, $content);
```

- code

- message

- is_success


## HTTP::Headers

```perl
my $headers = new HTTP::Headers(
    'name' => 'value', ...
);
```

- push_header

- remove_header


## HTTP::Status

- is_info

- is_success

- is_redirect

- is_client_error

- is_server_error

- is_error


## URI::URL

```perl
my $url = new URI::URL($url);
```

- scheme

- host

- port

- path

- query

- user

- password


## URI::Escape

- uri_escape

- uri_unescape