本文整理汇总了TypeScript中request-promise-native.put函数的典型用法代码示例。如果您正苦于以下问题:TypeScript put函数的具体用法?TypeScript put怎么用?TypeScript put使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了put函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
http.createServer((req, resp) => {
if (req.url === '/doodle.png') {
if (req.method === 'PUT') {
req.pipe(rpn.put('http://mysite.com/doodle.png'));
} else if (req.method === 'GET' || req.method === 'HEAD') {
rpn.get('http://mysite.com/doodle.png').pipe(resp);
}
}
});
示例2: switch
http.createServer((req, resp) => {
if (req.url === '/doodle.png') {
switch (req.method) {
case 'PUT':
req.pipe(rpn.put('http://mysite.com/doodle.png'));
break;
case 'GET':
case 'HEAD':
rpn.get('http://mysite.com/doodle.png').pipe(resp);
break;
}
}
});
示例3: rpn
})
.catch(console.error);
// The following examples from https://github.com/request/request
import * as fs from 'fs';
import * as http from 'http';
rpn('http://www.google.com', (error, response, body) => {
if (!error && response.statusCode === 200) {
console.log(body); // Show the HTML for the Google homepage.
}
});
rpn('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'));
fs.createReadStream('file.json').pipe(rpn.put('http://mysite.com/obj.json'));
rpn.get('http://google.com/img.png').pipe(rpn.put('http://mysite.com/img.png'));
rpn
.get('http://google.com/img.png')
.on('response', (response: any) => {
console.log(response.statusCode); // 200
console.log(response.headers['content-type']); // 'image/png'
})
.pipe(rpn.put('http://mysite.com/img.png'));
rpn
.get('http://mysite.com/doodle.png')
.on('error', (err: any) => {
console.log(err);