Http

Http

Source:

[W.I.P] HTTP handler module for WSH (Windows Script Host).

Requires

  • module:./Buffer.js

Methods

(static) request(url, optionsopt) → {string|Object}

Source:

[W.I.P] Requests the URL. Similar to Node.js http.request().

Example
var http = Wsh.Http; // Shorthand

// Ex 1. Auto JSON parsing
http.request('https://httpbin.org/ip');
// Returns: { origin: '111.222.333.444' }

// Ex 2. Basic Auth
http.request('https://httpbin.org/basic-auth', { auth: 'myUser:myPasswd' });

// Ex 3. Using proxy
http.request('https://httpbin.org/headers', {
  proxy: {
    host: '192.168.12.34',
    port: 8087,
    proxyAuth: 'proxyUser:proxyPassword'
});
// Returns:
// { headers: {
//     Accept: "\*\/*",
//     Accept-Language: "ja",
//     Host: "httpbin.org",
//     User-Agent: "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)",
//     X-Amzn-Trace-Id: "Root=1-1234abcd-12345678abcdefg123456789"
//   }
// }

// Ex 4. POST data
http.request('https://httpbin.org/post?argA=valA', {
  method: 'POST',
  dataToSend: 'formB=' + encodeURIComponent('value B')
});
// Returns:
// { args: { argA: "valA" },
//   data: "",
//   files: {},
//   form: { formB: "valB" },
//   headers: { ... },
//   json: null,
//   origin: "111.222.333.444",
//   url: "https://httpbin.org/post?%3FargA=valA" }
Parameters:
Name Type Attributes Description
url string

The URL to requrest.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
port number <optional>
80

Port of remote server.

auth string <optional>

Basic authentication. e.g. user:password to compute an Authorization header

method string <optional>
'GET'

The string specifying the HTTP request method.

dataToSend object <optional>
headers object <optional>
timeout number <optional>
0

The number specifying the socket timeout in milliseconds. This will set the timeout before the socket is connected. Default: 0 is no timeout

proxy object <optional>
Properties
Name Type Attributes Description
host string <optional>

'yourproxy',

port number <optional>

8087,

proxyAuth string <optional>

'proxyUser:proxyPass'

Returns:
Type
string | Object