Skip to main content

http.request(verb, URL, headers, body)

Returns a new generic HTTP request object

Availability

Agent

Parameters

Name Type Description
verb String The HTTP method required (eg. OPTIONS)
URL String The URL to which the HTTP request will be made
headers Table Optional table of additional HTTP headers
body String The body of the HTTP request, or an empty string

Returns

An httprequest object

Description

This method returns an httprequest object primed to make an HTTP/1.1 request with a custom method (verb) to the specified URL. The request isn’t issued until either sendsync() or sendasync() is called on the returned httprequest object.

Note This should not be used to make HEAD requests as this does not function correctly under Squirrel. For more information and a workaround, please see this Knowledgebase article.

The URL must start with "http://" or "https://" — ie. it must include the colon and the double-slash.

The headers can be any supported by HTTP, for instance:

{ "Content-Type" : "text/xml" }

Note that headers are specified without the colon.

The request body can be any string, but most servers will expect its content-type to be as described by the Content-Type header. If no request body is needed, use an empty string, "".

The most common HTTP request methods are provided by the convenience methods http.get(), http.put(), http.post() and http.httpdelete(). Use http.request() if you need an HTTP method other than those prepared for you — if you are accessing services using WebDAV or similar extensions to HTTP, for instance.

Example Code

Generic wrapper function to create an execute a generic HTTP request.