1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/env php
<?php
require_once dirname(__FILE__).'/../__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->parseStandardArguments();
$args->parse(
array(
array(
'name' => 'attach',
'param' => 'file',
'help' => pht('Attach a file to the request.'),
),
array(
'name' => 'url',
'wildcard' => true,
),
));
$uri = $args->getArg('url');
if (count($uri) !== 1) {
throw new PhutilArgumentUsageException(
pht('Specify exactly one URL to retrieve.'));
}
$uri = head($uri);
$method = 'GET';
$data = '';
$timeout = 30;
$future = id(new HTTPSFuture($uri, $data))
->setMethod($method)
->setTimeout($timeout);
$attach_file = $args->getArg('attach');
if ($attach_file !== null) {
$future->attachFileData(
'file',
Filesystem::readFile($attach_file),
basename($attach_file),
Filesystem::getMimeType($attach_file));
}
print_r($future->resolve());
|