本文整理匯總了TypeScript中unirest.post函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript post函數的具體用法?TypeScript post怎麽用?TypeScript post使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了post函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ImposterBuilder
unirest.delete('http://localhost:2525/imposters').end(() => {
unirest.post('http://localhost:2525/imposters').send(
JSON.stringify(new ImposterBuilder()
.port(port)
.addStub(new StubBuilder()
.addResponses(new ResponseBuilder().status(222).build()).build())
.build()))
.end(() => {
done();
});
});
示例2: before
before((done) => {
client = new UnirestHttpClient();
unirest.post('http://localhost:2525/imposters')
.send(JSON.stringify(
{
port: 4545,
protocol: 'http',
stubs: [
{
predicates: [{equals: {headers: {headerOne: 'valueOne'}, method: 'GET'}}],
responses: [{is: {body: 'Get response', statusCode: 200}}]
},
{
predicates: [{
equals: {
body: 'post rawBody',
headers: {headerTwo: 'valueTwo'},
method: 'POST'
}
}],
responses: [{is: {body: 'Post response', statusCode: 201}}]
},
{
predicates: [{
equals: {
body: 'put rawBody',
headers: {headerThree: 'valueThree'},
method: 'PUT'
}
}],
responses: [{is: {body: 'Put response', statusCode: 202}}]
},
{
predicates: [{equals: {headers: {headerFour: 'valueFour'}, method: 'HEAD'}}],
responses: [{is: {body: 'Head response', statusCode: 203}}]
},
{
predicates: [{equals: {headers: {headerFive: 'valueFive'}, method: 'DELETE'}}],
responses: [{is: {statusCode: 204}}]
},
{
responses: [{is: {statusCode: 205}}]
}
]
}
))
.end(() => {
done();
});
});
示例3: Error
return new Promise<number>((resolve, reject) => {
unirest
.post(`https://www.aliemu.com/wp-json/wp/v3/users/${userID}`)
.headers(HEADERS)
.type('json')
.send(data)
.end(
res =>
res.error
? reject(
new Error('Updating user in database failed.')
)
: resolve(200)
);
});
示例4:
var submitGame = (winPhoneArr: Array<string>, losePhoneArr: Array<string>, mvpPhone: string)=> {
var jsss = JSON.stringify({
"winUsers": winPhoneArr,
"loseUsers": losePhoneArr,
"key": '140fe1da9eab651944c',
"mvp": [mvpPhone],
"secret": 'jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI='
});
unirest.post('http://api.yuanqi.tv/ladder/enroll_result')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send({
"content": jsss
})
.end(function (response) {
console.log(response, response.body);
});
};
示例5: run
run(testPlans: Array<TestPlan>, http: HttpClient): Q.Promise<SummaryResults> {
let deferred = Q.defer<SummaryResults>();
unirest.post('http://localhost:7777')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send(JSON.stringify(testPlans))
.end((resp) => {
resp.body.requests.forEach((request) => {
this.reporter.addResult(request);
});
for (let i = 0; i < resp.body.errors; i++) {
this.reporter.addError();
}
deferred.resolve(null);
});
return deferred.promise;
}
示例6: resolve
return new Promise<number>(resolve => {
unirest
.post('https://api.sendgrid.com/v3/mail/send')
.header('Authorization', `Bearer ${process.env.SENDGRID_API_KEY}`)
.type('json')
.send({
personalizations: {
to: [
{
email: recipient,
},
],
},
from: {
email: 'admin@aliemu.com',
},
template_id: availableTemplates[templateName],
})
.end(response => {
resolve(response.statusCode);
});
});
示例7: verify
export function verify(req: express.Request, res: express.Response, next: Function) {
unirest.post("https://gruntroll-military-verification-v1.p.mashape.com/verify/active")
.header("X-Mashape-Key", process.env.MASHAPE)
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept", "text/plain")
.send(`date=${req.body.date}`)
.send(`dob=${req.body.dob}`)
.send(`name=${req.body.name}`)
.end((result) => {
let obj = JSON.parse(result.body);
if (obj.error != null) {
console.log(obj.error);
console.log(obj.message);
return next({ message: obj.message });
}
if (obj.is_active > 0 || obj.is_veteran > 0) {
User.findOneAndUpdate({ _id: req['payload']._id }, { $set: { verified: true } }, { new: true }, (err, user) => {
if (err) return next({ message: "The verification process is expired or unauthorized" });
if (user.email) {
let mailOptions = {
from: 'Veteran Connect <info@veteranconnect.co>',
to: user.email,
subject: `Welcome to Veteran Connect, ${user.firstName}!`,
html: welcome(user)
};
transporter.sendMail(mailOptions, (err) => {
if (err) {
console.log(err);
return next(err);
}
})
}
res.json({ token: user.generateJWT() });
})
} else if (obj.is_active == 0 && obj.is_veteran == 0) {
return next({ message: "Unable to verify your service!" });
}
});
}
示例8: function
adminRouter.get('/test', function (req: any, res: any) {
var unirest = require('unirest');
// var jsss = JSON.stringify({
// "winUsers": [10082, 10082, 10082, 10082],
// "loseUsers": [10082, 10082, 10082, 10082],
// "mvp": [10082]
// });
// var jsss = JSON.stringify({
// "winUsers": ["15502168938"],
// "loseUsers": ["15692173023"],
// "key": '140fe1da9eab651944c',
// "secret": 'jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=',
// "mvp": ["10082"]
// });
var jsss = JSON.stringify({
"winUsers": ["13616542277"],
"loseUsers": ["15692173023"],
"key": '140fe1da9eab651944c',
"secret": 'jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI='
});
unirest.post('http://api.yuanqi.tv/ladder/enroll_result')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send({
"content": jsss
})
.end(function (response) {
console.log(response, response.body);
});
var submitGame = (winPhoneArr: Array<string>, losePhoneArr: Array<string>, mvpPhone: string)=> {
var jsss = JSON.stringify({
"winUsers": winPhoneArr,
"loseUsers": losePhoneArr,
"key": '140fe1da9eab651944c',
"mvp": [mvpPhone],
"secret": 'jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI='
});
unirest.post('http://api.yuanqi.tv/ladder/enroll_result')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send({
"content": jsss
})
.end(function (response) {
console.log(response, response.body);
});
};
/////////////
var isNoPhone = false;
var gameArr = [];
var getBluePhoneArr = (playerDocArr, start = 0)=> {
var a = [];
for (var i = start; i < 4 + start; i++) {
var playerDoc = playerDocArr[i];
if (!playerDoc['phone']) {
isNoPhone = true;
console.log('no phone ', playerDoc.name);
}
else
a.push(playerDoc.phone + "");
}
return a;
};
var getRedPhoneArr = (playerDocArr)=> {
return getBluePhoneArr(playerDocArr, 4);
};
for (var i = 0; i < 14; i++) {
var gameDoc = db.game.dataMap[43001 + i];
var winPhoneArr = [];
var losePhoneArr = [];
var playerDocArr = db.player.getDocArr(gameDoc.playerIdArr);
console.log('playerDocArr ', playerDocArr);
if (gameDoc.isBlue) {
winPhoneArr = getBluePhoneArr(playerDocArr);
losePhoneArr = getRedPhoneArr(playerDocArr);
}
else {
losePhoneArr = getBluePhoneArr(playerDocArr);
winPhoneArr = getRedPhoneArr(playerDocArr);
}
var mvpPhone;
if (db.player.dataMap[gameDoc.mvp]['phone'])
mvpPhone = db.player.dataMap[gameDoc.mvp].phone + "";
console.log('winPhoneArr', winPhoneArr, 'losePhoneArr', losePhoneArr, 'mvp', mvpPhone);
gameArr.push(gameDoc);
// submitGame(winPhoneArr, losePhoneArr, mvpPhone);
}
console.log(gameArr);
if (isNoPhone)
res.send('no phone');
else
res.send("ok")
});