本文整理匯總了TypeScript中request.post函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript post函數的具體用法?TypeScript post怎麽用?TypeScript post使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了post函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
output.on('close', function () {
var options = {
method: 'POST',
url: url.resolve(serviceEndpoint, '/v2/build'),
encoding: 'binary'
};
console.log('Invoking the CloudAppX service...');
var req = request.post(options, function (err: any, resp: any, body: string) {
if (err) {
return callback && callback(err);
}
if (resp.statusCode !== 200) {
return callback && callback(new Error('Failed to create the package. The CloudAppX service returned an error - ' + resp.statusMessage + ' (' + resp.statusCode + '): ' + body));
}
fs.writeFile(outputPath, body, { 'encoding': 'binary' }, function (err) {
if (err) {
return callback && callback(err);
}
fs.unlink(zipFile, function (err) {
return callback && callback(err);
});
});
});
req.form().append('xml', fs.createReadStream(zipFile));
});
示例2: Promise
return new Promise((resolve,reject) => {
console.log(`posting ${url} form: ${JSON.stringify(formData)}`);
request.post({url:url,formData:formData}, (err,response,body)=> {
console.log(`post ${url} body ${JSON.stringify(formData)} err ${err} body ${body}`);
err && reject(err) || resolve(body);
})
});
示例3: opn
}).then((desc: string) => {
let data = {
"description": desc,
"public": true,
"files": {}
}
data.files[filename] = {"content": code};
let opts = {
url: 'https://api.github.com/gists',
body: data,
json: true,
headers: {
'User-Agent': 'request'
}
}
if (userName != null && userPass != null) {
opts['auth'] = {
user: userName,
pass: userPass
}
}
request.post(opts, (err, httpResponse, body) => {
vscode.window.showInformationMessage("Your File is published here: " + body.html_url);
opn(body.html_url)
});
})
示例4: Promise
let promise: Promise<INeo4jIndexResponse> = new Promise((resolve, reject) => {
let normalizedPropertyNamesArray: string[] = [];
if (typeof propertyNames === "string") {
normalizedPropertyNamesArray.push(propertyNames);
} else {
normalizedPropertyNamesArray = propertyNames;
}
let indexEndpointString: string = `${graphPaths.indexes}/${label}`;
try {
requestOptions.body = JSON.stringify({ "property_keys": normalizedPropertyNamesArray });
} catch (ex) {
reject(ex);
}
request.post(indexEndpointString, requestOptions, (err, response, body) => {
if (err) {
reject(err);
}
if (response.statusCode !== 200) {
reject(`Error creating index on label ${label}. HTTP Status Code: ${response.statusCode}. HTTP Body: ${body}`);
}
body = typeof body === "string" ? JSON.parse(body) : body;
resolve(body);
});
});
示例5: Promise
return new Promise((resolve, reject) => {
request.post('http://dpaste.com/api/v2/', { form: { content: code, syntax: syntax, title: title, expiry_days: 7 } }, (err, httpResponse, body) => {
if (err)
return reject(err);
resolve(body);
});
});
示例6: Promise
return new Promise((resolve, reject) => {
request.post("http://3ds.pokemon-gl.com/frontendApi/gbu/getSeasonPokemonDetail", {
headers: {
"Origin": "http://3ds.pokemon-gl.com",
"Referer": "http://3ds.pokemon-gl.com/battle/oras/",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": "CuBoid"
},
form: {
"languageId": "2",
"seasonId": "108",
"battleType": "2",
"timezone": "BST",
"pokemonId": pokemon,
"displayNumberWaza": "10",
"displayNumberTokusei": "3",
"displayNumberSeikaku": "10",
"displayNumberItem": "10",
"displayNumberLevel": "10",
"displayNumberPokemonIn": "10",
"displayNumberPokemonDown": "10",
"displayNumberPokemonDownWaza": "10",
"timestamp": Date.now().toString()
}
}, (err, response, body) => {
if (err) {
reject(err);
} else {
resolve(JSON.parse(body));
}
});
});
示例7: ApiCall
private ApiCall(apiType:string, data?) {
var that = this;
if (!this._statusBarItem) {
this._statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
}
request.post({
url: BASE_URL+apiType,
formData: data
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
switch(apiType) {
case API_SET_SNOOZE: case API_END_SNOOZE:
that._statusBarItem.text = "$(bell) Status set successfully!";
break;
case API_UPLOAD_FILES:
that._statusBarItem.text = "$(file-text) File sent successfully!";
break;
default:
that._statusBarItem.text = "$(comment) Message sent successfully!";
break;
}
that._statusBarItem.show();
setTimeout(function() { that._statusBarItem.hide()}, 5000 );
}
});
}
示例8: Logger
.on('file', (fields: Fields, file: any) => {
let formData = {
type: CONST.IMAGE_TYPES.AVATAR,
path: filePath,
file: {
value: fs.createReadStream(file.path),
options: {
filename: UTIL.renameFile(file.name)
}
}
}
request.post({
url: SERVERS.UPLOAD_SERVER,
formData
}, (err: Error, response, body) => {
if (err) console.log(err)
let fileName = JSON.parse(body).files[0],
filePath = path.join(now, fileName)
UserModel
.findByIdAndUpdate(creator, {avatar: filePath}, {new: true})
.then((user: IUser) => {
if (user) {
res.status(200).json(UTIL.getSignedUser(user))
new Logger(log)
}
})
.catch((err: Error) => {
new Err(res, err, log)
})
})
})
示例9: it
it('should not authorize without header', (done) => {
request.post('http://localhost:5674/authorization/methods/profile',
(error, response, body) => {
expect(response.statusCode).to.eq(401);
done();
});
});