本文整理汇总了TypeScript中http.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: get
get(templateUrl: string): Promise<string> {
let completer: PromiseCompleter<string> = PromiseWrapper.completer(),
parsedUrl = url.parse(templateUrl);
http.get(templateUrl, (res) => {
res.setEncoding('utf8');
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
var status = res.statusCode === 1223 ? 204 : res.statusCode;
if (200 <= status && status <= 300) {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
completer.resolve(data);
});
} else {
completer.reject(`Failed to load ${templateUrl}`, null);
}
// consume response body
res.resume();
}).on('error', (e) => {
completer.reject(`Failed to load ${templateUrl}`, null);
});
return completer.promise;
}
开发者ID:APiercey,项目名称:Rails-Angular2-JWT-Auth-Demo,代码行数:32,代码来源:node_xhr_impl.ts
示例2: processFile
function processFile(file: string, cb: (err: Error) => any) {
let outputFilename = file;
if (startsWith(outputFilename, buildPath)) {
// Project build files are served on the build port
outputFilename = outputFilename.substr(buildPath.length);
file = `${options.baseURL}:${options.buildPort}${file}`;
} else {
// Other files are served on the main port
file = `${options.baseURL}:${options.mainPort}${file}`;
if (startsWith(outputFilename, systemsPath)) {
// Output system files at the root
outputFilename = outputFilename.substr(outputFilename.indexOf("/", systemsPath.length));
}
}
outputFilename = outputFilename.replace(/\//g, path.sep);
const outputPath = `${options.outputFolder}${outputFilename}`;
exportWindow.webContents.send("set-export-status", { text: outputPath });
http.get(file, (response) => {
mkdirp(path.dirname(outputPath), (err: Error) => {
const localFile = fs.createWriteStream(outputPath);
localFile.on("finish", () => { progress++; exportWindow.setProgressBar(progress / progressMax); cb(null); });
response.pipe(localFile);
});
}).on("error", cb);
}
开发者ID:AgileJoshua,项目名称:superpowers-app,代码行数:28,代码来源:ipc.ts
示例3: fetch
function fetch(){
// url options
let urlOpts: Object | url.Url = {
host: 'stackoverflow.com',
path: '/',
port: '80'
};
// Complete url when inputting command argument
if (process.argv[2]) {
if (!process.argv[2].match('http://')) {
process.argv[2] = 'http://' + process.argv[2];
}
urlOpts = url.parse(process.argv[2]);
}
// Start to crawl
http.get(urlOpts, (res) => {
res.on('data', (chunk: Buffer) => {
console.log(chunk.toString());
}).on('error', (e: Error) => {
console.log('error:' + e.message);
});
});
}
开发者ID:TonyPythoneer,项目名称:node-cookbook,代码行数:25,代码来源:app.ts
示例4: Promise
return new Promise((resolve, reject) => {
http.get(`http://localhost:${port}/wd/hub/sessions`, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
let result = undefined;
console.log(data);
try {
//result = JSON.parse(data);
result = data;
} catch (error) {
}
resolve(result);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
resolve(undefined);
});
});
开发者ID:NativeScript,项目名称:nativescript-dev-appium,代码行数:29,代码来源:utils.ts
示例5: get
get(templateUrl: string): Promise<string> {
const completer: PromiseCompleter<string> = PromiseWrapper.completer();
const parsedUrl = url.parse(templateUrl);
http.get(parsedUrl, (res) => {
res.setEncoding('utf8');
const status = res.statusCode;
if (200 <= status && status <= 300) {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
completer.resolve(data);
});
} else {
completer.reject(`Failed to load ${templateUrl}`, null);
}
// consume response body
res.resume();
}).on('error', (e) => {
completer.reject(`Failed to load ${templateUrl}`, null);
});
return completer.promise;
}
开发者ID:JoshAntBrown,项目名称:universal,代码行数:31,代码来源:node_xhr_impl.ts
示例6: while
app.get('/findImages', (req, res) => {
console.log('getting images from' + req.query['url']);
let req2 = http.get(url.parse(req.query['url']), urlMessage => {
console.log("Got response: " + urlMessage.statusCode);
let text = "";
urlMessage.on('data', (chunk: string) => {
text += chunk;
});
urlMessage.on('end', () => {
console.log(text);
const imageTagRegEx = /<img[^>]+src=[\"\']([^\'\"]+)[\"\']/g;
let match: RegExpMatchArray;
let matches: string[] = [];
while (match = imageTagRegEx.exec(text)) {
matches.push(match[1]);
}
res.write(JSON.stringify(matches));
res.end();
});
}).on('error', function(a,e) {
console.log("Got error: " + e.message);
});
});
开发者ID:ZombieHippie,项目名称:m,代码行数:30,代码来源:app.ts
示例7: record_fetch_proc_s4
// ---------------------------------------------------------------
function record_fetch_proc_s4 (options_in,key_in)
{
http.get(options_in, function(res)
{
// console.log("Got response: " + res.statusCode)
// console.log('HEADERS: ' + JSON.stringify(res.headers))
res.setEncoding('utf8')
var json_str = ""
res.on('data', function (chunk) {
json_str += chunk
})
res.on('end', function ()
{
var unit_aa = JSON.parse (json_str)
var str_out: string = key_in + '\t'
str_out += unit_aa['name'] + '\t'
str_out += unit_aa['population'] + '\t'
str_out += unit_aa['date_mod']
console.log (str_out)
})
}).on('error', function(e)
{
console.log("Got error: " + e.message)
})
}
开发者ID:ekzemplaro,项目名称:data_base_language,代码行数:30,代码来源:riak_read.ts
示例8: find_neighbours
export function find_neighbours(id: string, port : number, callback : (TransferNodePair) => void) : void
{
// Setup the HTTP request
var options = {
host: 'localhost',
port: port,
path: '/find_neighbours?id=' + id
};
// ... and fire!
http.get(options, function(res)
{
console.log("Got response code: " + res.statusCode);
res.on("data", function(chunk)
{
console.log("Got response: " + chunk);
var object : TransferNodePair = JSON.parse(chunk);
callback(object);
});
}).on('error', function(e)
{
console.error("Error while finding neighbours: " + e.message);
console.error("Terminating");
process.exit(1);
});
}
开发者ID:MortenSoerensen,项目名称:IoT-P2P-2015,代码行数:25,代码来源:ChordHelper.ts
示例9: Promise
return new Promise(function (resolve, reject){
if (self.status === JobStatus.NotBuilt || self.status === JobStatus.Disabled) {
reject(new Error('Job \'' + self.name + '\' status is ' + JobStatus[self.status]));
} else {
var buildResultsUrl = self.rootUrl + 'api/json?tree=builds[number,result,url,fullDisplayName,timestamp,estimatedDuration,duration,builtOn,building]';
http.get(buildResultsUrl, res => {
debug('getBuildResults for \'' + self.name + '\' status code: ' + res.statusCode);
if (res.statusCode !== 200) {
reject(new Error('Could not get build results'));
} else {
var responseBody = '';
res.on('data', chunk => {
responseBody += chunk;
});
res.on('end', () => {
try {
var json = JSON.parse(responseBody);
Promise.map(json.builds, jsonResult => {
self.buildResults = [];
var b = buildresult.fromJson(jsonResult);
self.buildResults.push(b);
return b;
}).then(resolve);
} catch (err) {
var error = new Error('Could not parse JSON for ' + self.name + ': ' + err.message);
error.stack = err.stack;
reject(error);
}
});
}
});
}
});
开发者ID:pierreca,项目名称:dashboards,代码行数:34,代码来源:job.ts
示例10: Promise
return new Promise((resolve, reject) => {
try {
http.get({
'host': 'wttr.in',
'path': uri.path.replace(/ /g, '_'),
'headers': {
'User-Agent': 'curl/7.43.0'
}
}, function(response) {
// Continuously update stream with data
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
var result = 'Via http://wttr.in' + uri.path + '\r\n\r\n';
result += stripColorCode(body);
resolve(result);
});
response.on('error', function(error) {
reject(error);
});
});
} catch (ex) {
reject(ex);
}
});
开发者ID:austin-----,项目名称:vscode-weather-forecast,代码行数:27,代码来源:extension.ts
注:本文中的http.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论