{
    "content": [
        {
            "type": "text",
            "text": "# HTTP::Request::Common (perldoc)\n\n## NAME\n\nHTTP::Request::Common - Construct common HTTP::Request objects\n\n## SYNOPSIS\n\nuse HTTP::Request::Common;\n$ua = LWP::UserAgent->new;\n$ua->request(GET 'http://www.sn.no/');\n$ua->request(POST 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PATCH 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PUT 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(OPTIONS 'http://somewhere/foo', foo => bar, bar => foo);\n\n## DESCRIPTION\n\nThis module provides functions that return newly created \"HTTP::Request\" objects. These\nfunctions are usually more convenient to use than the standard \"HTTP::Request\" constructor for\nthe most common requests.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **SEE ALSO**\n- **AUTHOR**\n- **COPYRIGHT AND LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "HTTP::Request::Common",
        "section": "",
        "mode": "perldoc",
        "summary": "HTTP::Request::Common - Construct common HTTP::Request objects",
        "synopsis": "use HTTP::Request::Common;\n$ua = LWP::UserAgent->new;\n$ua->request(GET 'http://www.sn.no/');\n$ua->request(POST 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PATCH 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PUT 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(OPTIONS 'http://somewhere/foo', foo => bar, bar => foo);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 175,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "HTTP::Request::Common - Construct common HTTP::Request objects\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 6.36\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use HTTP::Request::Common;\n$ua = LWP::UserAgent->new;\n$ua->request(GET 'http://www.sn.no/');\n$ua->request(POST 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PATCH 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(PUT 'http://somewhere/foo', foo => bar, bar => foo);\n$ua->request(OPTIONS 'http://somewhere/foo', foo => bar, bar => foo);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This module provides functions that return newly created \"HTTP::Request\" objects. These\nfunctions are usually more convenient to use than the standard \"HTTP::Request\" constructor for\nthe most common requests.\n\nNote that LWP::UserAgent has several convenience methods, including \"get\", \"head\", \"delete\",\n\"post\" and \"put\".\n\nThe following functions are provided:\n\nGET $url\nGET $url, Header => Value,...\nThe \"GET\" function returns an HTTP::Request object initialized with the \"GET\" method and the\nspecified URL. It is roughly equivalent to the following call\n\nHTTP::Request->new(\nGET => $url,\nHTTP::Headers->new(Header => Value,...),\n)\n\nbut is less cluttered. What is different is that a header named \"Content\" will initialize\nthe content part of the request instead of setting a header field. Note that GET requests\nshould normally not have a content, so this hack makes more sense for the \"PUT\", \"PATCH\" and\n\"POST\" functions described below.\n\nThe \"get(...)\" method of LWP::UserAgent exists as a shortcut for \"$ua->request(GET ...)\".\n\nHEAD $url\nHEAD $url, Header => Value,...\nLike GET() but the method in the request is \"HEAD\".\n\nThe \"head(...)\" method of LWP::UserAgent exists as a shortcut for \"$ua->request(HEAD ...)\".\n\nDELETE $url\nDELETE $url, Header => Value,...\nLike \"GET\" but the method in the request is \"DELETE\". This function is not exported by\ndefault.\n\nPATCH $url\nPATCH $url, Header => Value,...\nPATCH $url, $formref, Header => Value,...\nPATCH $url, Header => Value,..., Content => $formref\nPATCH $url, Header => Value,..., Content => $content\nThe same as \"POST\" below, but the method in the request is \"PATCH\".\n\nPUT $url\nPUT $url, Header => Value,...\nPUT $url, $formref, Header => Value,...\nPUT $url, Header => Value,..., Content => $formref\nPUT $url, Header => Value,..., Content => $content\nThe same as \"POST\" below, but the method in the request is \"PUT\"\n\nOPTIONS $url\nOPTIONS $url, Header => Value,...\nOPTIONS $url, $formref, Header => Value,...\nOPTIONS $url, Header => Value,..., Content => $formref\nOPTIONS $url, Header => Value,..., Content => $content\nThe same as \"POST\" below, but the method in the request is \"OPTIONS\"\n\nPOST $url\nPOST $url, Header => Value,...\nPOST $url, $formref, Header => Value,...\nPOST $url, Header => Value,..., Content => $formref\nPOST $url, Header => Value,..., Content => $content\n\"POST\", \"PATCH\" and \"PUT\" all work with the same parameters.\n\n%data = ( title => 'something', body => something else' );\n$ua = LWP::UserAgent->new();\n$request = HTTP::Request::Common::POST( $url, [ %data ] );\n$response = $ua->request($request);\n\nThey take a second optional array or hash reference parameter $formref. The content can\nalso be specified directly using the \"Content\" pseudo-header, and you may also provide the\n$formref this way.\n\nThe \"Content\" pseudo-header steals a bit of the header field namespace as there is no way to\ndirectly specify a header that is actually called \"Content\". If you really need this you\nmust update the request returned in a separate statement.\n\nThe $formref argument can be used to pass key/value pairs for the form content. By default\nwe will initialize a request using the \"application/x-www-form-urlencoded\" content type.\nThis means that you can emulate an HTML <form> POSTing like this:\n\nPOST 'http://www.perl.org/survey.cgi',\n[ name   => 'Gisle Aas',\nemail  => 'gisle@aas.no',\ngender => 'M',\nborn   => '1964',\nperc   => '3%',\n];\n\nThis will create an HTTP::Request object that looks like this:\n\nPOST http://www.perl.org/survey.cgi\nContent-Length: 66\nContent-Type: application/x-www-form-urlencoded\n\nname=Gisle%20Aas&email=gisle%40aas.no&gender=M&born=1964&perc=3%25\n\nMultivalued form fields can be specified by either repeating the field name or by passing\nthe value as an array reference.\n\nThe POST method also supports the \"multipart/form-data\" content used for *Form-based File\nUpload* as specified in RFC 1867. You trigger this content format by specifying a content\ntype of 'form-data' as one of the request headers. If one of the values in the $formref is\nan array reference, then it is treated as a file part specification with the following\ninterpretation:\n\n[ $file, $filename, Header => Value... ]\n[ undef, $filename, Header => Value,..., Content => $content ]\n\nThe first value in the array ($file) is the name of a file to open. This file will be read\nand its content placed in the request. The routine will croak if the file can't be opened.\nUse an \"undef\" as $file value if you want to specify the content directly with a \"Content\"\nheader. The $filename is the filename to report in the request. If this value is undefined,\nthen the basename of the $file will be used. You can specify an empty string as $filename if\nyou want to suppress sending the filename when you provide a $file value.\n\nIf a $file is provided by no \"Content-Type\" header, then \"Content-Type\" and\n\"Content-Encoding\" will be filled in automatically with the values returned by\n\"LWP::MediaTypes::guessmediatype()\"\n\nSending my ~/.profile to the survey used as example above can be achieved by this:\n\nPOST 'http://www.perl.org/survey.cgi',\nContentType => 'form-data',\nContent      => [ name  => 'Gisle Aas',\nemail => 'gisle@aas.no',\ngender => 'M',\nborn   => '1964',\ninit   => [\"$ENV{HOME}/.profile\"],\n]\n\nThis will create an HTTP::Request object that almost looks this (the boundary and the\ncontent of your ~/.profile is likely to be different):\n\nPOST http://www.perl.org/survey.cgi\nContent-Length: 388\nContent-Type: multipart/form-data; boundary=\"6G+f\"\n\n--6G+f\nContent-Disposition: form-data; name=\"name\"\n\nGisle Aas\n--6G+f\nContent-Disposition: form-data; name=\"email\"\n\ngisle@aas.no\n--6G+f\nContent-Disposition: form-data; name=\"gender\"\n\nM\n--6G+f\nContent-Disposition: form-data; name=\"born\"\n\n1964\n--6G+f\nContent-Disposition: form-data; name=\"init\"; filename=\".profile\"\nContent-Type: text/plain\n\nPATH=/local/perl/bin:$PATH\nexport PATH\n\n--6G+f--\n\nIf you set the $DYNAMICFILEUPLOAD variable (exportable) to some TRUE value, then you get\nback a request object with a subroutine closure as the content attribute. This subroutine\nwill read the content of any files on demand and return it in suitable chunks. This allow\nyou to upload arbitrary big files without using lots of memory. You can even upload infinite\nfiles like /dev/audio if you wish; however, if the file is not a plain file, there will be\nno \"Content-Length\" header defined for the request. Not all servers (or server applications)\nlike this. Also, if the file(s) change in size between the time the \"Content-Length\" is\ncalculated and the time that the last chunk is delivered, the subroutine will \"Croak\".\n\nThe \"post(...)\" method of LWP::UserAgent exists as a shortcut for \"$ua->request(POST ...)\".\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "HTTP::Request, LWP::UserAgent\n\nAlso, there are some examples in \"EXAMPLES\" in HTTP::Request that you might find useful. For\nexample, batch requests are explained there.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Gisle Aas <gisle@activestate.com>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENSE": {
                "content": "This software is copyright (c) 1994 by Gisle Aas.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
                "subsections": []
            }
        }
    }
}