@@ -310,21 +310,27 @@ __END__
310
310
$ua = LWP::UserAgent->new;
311
311
$ua->request(GET 'http://www.sn.no/');
312
312
$ua->request(POST 'http://somewhere/foo', [foo => bar, bar => foo]);
313
+ $ua->request(PATCH 'http://somewhere/foo', [foo => bar, bar => foo]);
314
+ $ua->request(PUT 'http://somewhere/foo', [foo => bar, bar => foo]);
313
315
314
316
=head1 DESCRIPTION
315
317
316
- This module provide functions that return newly created C<HTTP::Request >
318
+ This module provides functions that return newly created C<HTTP::Request >
317
319
objects. These functions are usually more convenient to use than the
318
- standard C<HTTP::Request > constructor for the most common requests. The
319
- following functions are provided:
320
+ standard C<HTTP::Request > constructor for the most common requests.
321
+
322
+ Note that L<LWP::UserAgent> has several convenience methods, including
323
+ C<get > , C<head > , C<delete > , C<post > and C<put > .
324
+
325
+ The following functions are provided:
320
326
321
327
=over 4
322
328
323
329
=item GET $url
324
330
325
331
=item GET $url, Header => Value,...
326
332
327
- The GET() function returns an C <HTTP::Request > object initialized with
333
+ The C< GET > function returns an L <HTTP::Request> object initialized with
328
334
the "GET" method and the specified URL. It is roughly equivalent to the
329
335
following call
330
336
@@ -336,49 +342,51 @@ following call
336
342
but is less cluttered. What is different is that a header named
337
343
C<Content > will initialize the content part of the request instead of
338
344
setting a header field. Note that GET requests should normally not
339
- have a content, so this hack makes more sense for the PUT(), PATCH()
340
- and POST() functions described below.
345
+ have a content, so this hack makes more sense for the C< PUT > , C< PATCH >
346
+ and C< POST > functions described below.
341
347
342
- The get(...) method of C <LWP::UserAgent > exists as a shortcut for
343
- $ua->request(GET ...).
348
+ The C< get(...) > method of L <LWP::UserAgent> exists as a shortcut for
349
+ C<< $ua->request(GET ...) >> .
344
350
345
351
=item HEAD $url
346
352
347
353
=item HEAD $url, Header => Value,...
348
354
349
355
Like GET() but the method in the request is "HEAD".
350
356
351
- The head(...) method of "LWP::UserAgent" exists as a shortcut for
352
- $ua->request(HEAD ...).
353
-
354
- =item PUT $url
355
-
356
- =item PUT $url, Header => Value,...
357
+ The C<head(...) > method of L<LWP::UserAgent> exists as a shortcut for
358
+ C<< $ua->request(HEAD ...) >>.
357
359
358
- =item PUT $url, Header => Value,..., Content => $content
360
+ =item DELETE $url
359
361
360
- Like GET() but the method in the request is "PUT" .
362
+ =item DELETE $url, Header => Value,.. .
361
363
362
- The content of the request can be specified using the "Content"
363
- pseudo-header. This steals a bit of the header field namespace as
364
- there is no way to directly specify a header that is actually called
365
- "Content". If you really need this you must update the request
366
- returned in a separate statement.
364
+ Like C<GET > but the method in the request is C<DELETE > . This function
365
+ is not exported by default.
367
366
368
367
=item PATCH $url
369
368
370
369
=item PATCH $url, Header => Value,...
371
370
371
+ =item PATCH $url, $form_ref, Header => Value,...
372
+
373
+ =item PATCH $url, Header => Value,..., Content => $form_ref
374
+
372
375
=item PATCH $url, Header => Value,..., Content => $content
373
376
374
- Like PUT() but the method in the request is " PATCH" .
377
+ The same as C< POST > below, but the method in the request is C< PATCH > .
375
378
376
- =item DELETE $url
379
+ =item PUT $url
377
380
378
- =item DELETE $url, Header => Value,...
381
+ =item PUT $url, Header => Value,...
379
382
380
- Like GET() but the method in the request is "DELETE". This function
381
- is not exported by default.
383
+ =item PUT $url, $form_ref, Header => Value,...
384
+
385
+ =item PUT $url, Header => Value,..., Content => $form_ref
386
+
387
+ =item PUT $url, Header => Value,..., Content => $content
388
+
389
+ The same as C<POST > below, but the method in the request is C<PUT >
382
390
383
391
=item POST $url
384
392
@@ -390,13 +398,24 @@ is not exported by default.
390
398
391
399
=item POST $url, Header => Value,..., Content => $content
392
400
393
- This works mostly like PUT() with "POST" as the method, but this
394
- function also takes a second optional array or hash reference
395
- parameter $form_ref. As for PUT() the content can also be specified
396
- directly using the "Content" pseudo-header, and you may also provide
397
- the $form_ref this way.
401
+ C<POST > , C<PATCH > and C<PUT > all work with the same parameters.
402
+
403
+ %data = ( title => 'something', body => something else' );
404
+ $ua = LWP::UserAgent->new();
405
+ $request = HTTP::Request::Common::POST( $url, [ %data ] );
406
+ $response = $ua->request($request);
407
+
408
+ They take a second optional array or hash reference
409
+ parameter C<$form_ref > . The content can also be specified
410
+ directly using the C<Content > pseudo-header, and you may also provide
411
+ the C<$form_ref > this way.
412
+
413
+ The C<Content > pseudo-header steals a bit of the header field namespace as
414
+ there is no way to directly specify a header that is actually called
415
+ "Content". If you really need this you must update the request
416
+ returned in a separate statement.
398
417
399
- The $form_ref argument can be used to pass key/value pairs for the
418
+ The C< $form_ref > argument can be used to pass key/value pairs for the
400
419
form content. By default we will initialize a request using the
401
420
C<application/x-www-form-urlencoded > content type. This means that
402
421
you can emulate an HTML E<lt> form> POSTing like this:
@@ -409,7 +428,7 @@ you can emulate an HTML E<lt>form> POSTing like this:
409
428
perc => '3%',
410
429
];
411
430
412
- This will create an HTTP::Request object that looks like this:
431
+ This will create an L< HTTP::Request> object that looks like this:
413
432
414
433
POST http://www.perl.org/survey.cgi
415
434
Content-Length: 66
@@ -423,7 +442,7 @@ name or by passing the value as an array reference.
423
442
The POST method also supports the C<multipart/form-data > content used
424
443
for I<Form-based File Upload > as specified in RFC 1867. You trigger
425
444
this content format by specifying a content type of C<'form-data' > as
426
- one of the request headers. If one of the values in the $form_ref is
445
+ one of the request headers. If one of the values in the C< $form_ref > is
427
446
an array reference, then it is treated as a file part specification
428
447
with the following interpretation:
429
448
@@ -441,7 +460,7 @@ want to suppress sending the filename when you provide a $file value.
441
460
442
461
If a $file is provided by no C<Content-Type > header, then C<Content-Type >
443
462
and C<Content-Encoding > will be filled in automatically with the values
444
- returned by LWP::MediaTypes::guess_media_type()
463
+ returned by C< LWP::MediaTypes::guess_media_type() >
445
464
446
465
Sending my F<~/.profile> to the survey used as example above can be
447
466
achieved by this:
@@ -455,7 +474,7 @@ achieved by this:
455
474
init => ["$ENV{HOME}/.profile"],
456
475
]
457
476
458
- This will create an HTTP::Request object that almost looks this (the
477
+ This will create an L< HTTP::Request> object that almost looks this (the
459
478
boundary and the content of your F<~/.profile> is likely to be
460
479
different):
461
480
@@ -488,20 +507,20 @@ different):
488
507
489
508
--6G+f--
490
509
491
- If you set the $DYNAMIC_FILE_UPLOAD variable (exportable) to some TRUE
510
+ If you set the C< $DYNAMIC_FILE_UPLOAD > variable (exportable) to some TRUE
492
511
value, then you get back a request object with a subroutine closure as
493
512
the content attribute. This subroutine will read the content of any
494
513
files on demand and return it in suitable chunks. This allow you to
495
514
upload arbitrary big files without using lots of memory. You can even
496
515
upload infinite files like F</dev/audio> if you wish; however, if
497
- the file is not a plain file, there will be no Content-Length header
516
+ the file is not a plain file, there will be no C< Content-Length > header
498
517
defined for the request. Not all servers (or server
499
518
applications) like this. Also, if the file(s) change in size between
500
- the time the Content-Length is calculated and the time that the last
519
+ the time the C< Content-Length > is calculated and the time that the last
501
520
chunk is delivered, the subroutine will C<Croak > .
502
521
503
- The post(...) method of " LWP::UserAgent" exists as a shortcut for
504
- $ua->request(POST ...).
522
+ The C< post(...) > method of L< LWP::UserAgent> exists as a shortcut for
523
+ C<< $ua->request(POST ...) >> .
505
524
506
525
=back
507
526
0 commit comments