本文整理汇总了TypeScript中superagent.agent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript agent函数的具体用法?TypeScript agent怎么用?TypeScript agent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了agent函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: gsUploadByPost
export async function gsUploadByPost(formData:any){
// expects an object with formData( the file(s)),
function gsUploadByPostErrorHandler(err:any){
alert('An error occurred while posting the file to GenomeSpace');
};
function gsUploadByPostCompleteHandler(responseObj:any){
if (typeof responseObj == "string"){
responseObj = JSON.parse(responseObj);
}
let newWin = window.open(responseObj.completionUrl, "GenomeSpace Upload", "height=340px,width=550px");
(newWin as any).focus();
};
let params = {
url: jsuiRoot + '/postToGenomeSpace', //server script to process data
type: 'POST',
crossDomain: true,
success: gsUploadByPostCompleteHandler,
error: gsUploadByPostErrorHandler,
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
};
// $.ajax(params);
let req = request.agent()
.post(params.url, (err, res) => err ? params.error(err) : params.success(res))
.send(params.data);
}
示例2: req
static get req() {
if (Tools.isNode) {
//const agent = new http.Agent()
//agent.maxSockets = 100
return request
.agent()
//.use(sdebug(console.info))
.set({ "Accept-Encoding" : "gzip,deflate" })
}
else {
return request
}
}
示例3: constructor
constructor(opts: {host: string, context?: string, username?: string, password?: string, authType?: AuthType}) {
this.host = opts.host;
opts.context = opts.context || '';
if (opts.context.length && opts.context[0] !== '/') opts.context = '/' + opts.context;
this.context = opts.context;
this.username = opts.username;
this.password = opts.password;
this.authType = opts.authType || opts.username && 'basic' || 'no';
if (this.authType === 'basic' && !(opts.username && opts.password)) {
throw new Error('BasicAuth needs both of username and password');
}
this.client = superagent.agent();
this.cookieAuth = this.makeCookieAuthPromise();
}
示例4: require
// and https://github.com/visionmedia/superagent/blob/master/Readme.md
request
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end((err, res) => {
if (res.ok) {
console.log('yay got ' + JSON.stringify(res.body));
} else {
console.log('Oh no! error ' + res.text);
}
});
var agent = request.agent();
agent
.post('/api/pet')
.send({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end((err, res) => {
if (res.error) {
console.log('oh no ' + res.error.message);
} else {
console.log('got ' + res.status + ' response');
}
});
// Plugins
var nocache = require('superagent-no-cache');
示例5:
request
.post('/api/pet')
.send({name: 'Manny', species: 'cat'})
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.agent(httpsAgent)
.end((err, res) => {
if (res.ok) {
console.log('yay got ' + JSON.stringify(res.body));
} else {
console.log('Oh no! error ' + res.text);
}
});
const agent = request.agent();
agent
.post('/api/pet')
.send({name: 'Manny', species: 'cat'})
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end((err, res) => {
if (res.error) {
console.log('oh no ' + res.error.message);
} else {
console.log('got ' + res.status + ' response');
}
});
const callback = (err: any, res: request.Response) => {};