content¶
- HTTPRequest#content(data)¶
Arguments: - data –
Any content to send along with a PUT or POST request.
The http library allows scripts to fetch and push data from and to the internet. It is a high-level interface with the Socket object. The library implements a good subset of the HTTP 1.1 protocol.
#include "extendables/extendables.jsx";
var http = require("http");
var response = http.get("http://www.w3c.org")
if (response.status_code == 200) {
$.writeln(response.body);
} else {
$.writeln("Connection failed");
}
Aside from high-level functions like get and post, there’s also a lower-level interface providing, if you happen to need more flexibility.
var req = new http.HTTPRequest("GET", "http://nytimes.com");
req.follow_redirects(false);
var timeout = req.timeout();
req.timeout(10);
$.writeln("Changing timeout from {} to {} seconds".format(timeout, 10));
req.header("User-Agent", "My ExtendScript app");
var res = req.do();
$.writeln(res.status == 200);
The Socket object is available in Adobe Bridge, Adobe InDesign, Adobe InCopy, Adobe After Effects and Adobe Photoshop, and you may also use it in the ExtendScript Toolkit. No luck for Illustrator fiends.
| Arguments: |
|
|---|
properties will do.
param Number timeout: How long before the http client should give up. (Default: 1)
Performs a DELETE request on the specified resource.
| Arguments: |
|
|---|
Performs a GET request on the specified resource.
Tests whether the application has access to the internet. If not, this might either imply that the user is simply not connected, or otherwise that a firewall is blocking internet access for the active Creative Suite app.
| Arguments: |
|
|---|
Performs a HEAD request on the specified resource. Similar to a GET request, but only returns the http headers.
| Arguments: |
|
|---|
will be passed along unchanged.
param Object basic_auth: Basic authentication — any object with username and password
properties will do.
param Number timeout: How long before the http client should give up. (Default: 5)
Performs a POST request on the specified resource.
| Arguments: |
|
|---|
will be passed along unchanged.
param Object basic_auth: Basic authentication — any object with username and password
properties will do.
param Number timeout: How long before the http client should give up. (Default: 1)
Performs a PUT request on the specified resource. PUT requests are like POST requests, but idempotent.
An incomplete but “good enough” implementation of the hypertext transfer protocol for the client side. This is a lower-level interface. It feeds the get(), head(), post(), put() and del() convenience functions.
Supports:
Soon:
Most likely never:
HTTPRequest objects are entirely getter/setter-based, so e.g. use req.method() to get the current request method, and use req.method("POST") to change the request method.
var http = require("http");
var example = "http://www.example.com"
var response = http.HTTPRequest("GET", example);
if (response.status == 200) {
$.writeln(response.body);
} else {
$.writeln("Couldn't fetch {}".format(example));
}
| Arguments: |
|
|---|
| Arguments: |
|
|---|
Any content to send along with a PUT or POST request.
| Arguments: |
|
|---|
The character encoding in which to send this request, which is also the preferred response encoding.
| Arguments: |
|
|---|
Whether to follow redirects when requesting a resource. By default, true for GET and HEAD requests, false for POST and PUT requests.
| Arguments: |
|
|---|
Use the header method instead when fetching or changing a single header.
The headers for this request. By default, these headers are included:
| Arguments: |
|
|---|
How much redirects the http client should follow before giving up.
| Arguments: |
|
|---|
The request method. One of GET, HEAD, POST, PUT or DELETE. GET by default.
| Arguments: |
|
|---|
Whether to establish a persistent connection. False by default, and best left that way.
| Arguments: |
|
|---|
The server port the request should be directed to.
The response to an HTTP request. These are returned by HTTPRequest() objects, you should never have to construct them yourself.
| Arguments: |
|
|---|
Available as for_request on the response object.
If redirected, distinguishes between requests that should be re-issued with a GET request (303) and those that should be re-issued as-is (all the others).