Requires
- module:./Buffer.js
Methods
(static) request(url, optionsopt) → {string|Object}
[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
|
Returns:
- Type
- string | Object