本文整理汇总了TypeScript中request-promise.post函数的典型用法代码示例。如果您正苦于以下问题:TypeScript post函数的具体用法?TypeScript post怎么用?TypeScript post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: queryTradeInfo
/**
* 提供會員系統查詢 O'Pay 訂單資訊,可透過此 API 來過濾是否為有效訂單,更多應用請參考 [FAQ](https://forum.allpay.com.tw/forum.php?mod=viewthread&tid=95&extra=page%3D1)
*/
public async queryTradeInfo(info: ITradeInfo) {
let body = extend<ITradeInfo>(
{
TimeStamp: Math.floor(Date.now() / 1000),
MerchantID: this.config.MerchantID,
PlatformID: ""
},
info
);
let check = new V();
check.verify(body, {
TimeStamp: [V.isNumber],
MerchantID: [V.isString, V.limitLength(1, 10)],
MerchantTradeNo: [
V.isString,
V.limitLength(1, 20),
V.isNumberOrEnglishLetter
]
});
if (check.invalid) throw check.errorMessage;
body.CheckMacValue = getMacValue(body, this.config);
let data = qs.stringify(body);
return request
.post(this.config.QueryTradeInfoUrl, {
form: body,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": Buffer.byteLength(data)
},
json: false
})
.then(qs.parse);
}
示例2: post
private async post(url:string, dtoContract:any, data:any) {
try {
const json = await rp.post({
url: Contacter.protocol(this.port) + this.fullyQualifiedHost + url,
body: data,
json: true,
timeout: this.options.timeout
});
// Prevent JSON injection
return sanitize(json, dtoContract);
} catch (e) {
throw e.error;
}
}
示例3: getAccessTokenAsync
// Redeem the authorization code for an access token
public async getAccessTokenAsync(code: string): Promise<UserToken> {
let params = {
grant_type: "authorization_code",
code: code,
client_id: this.clientId,
client_secret: this.clientSecret,
redirect_uri: config.get("app.baseUri") + callbackPath,
} as any;
let responseBody = await request.post({ url: accessTokenUrl, form: params, json: true });
return {
accessToken: responseBody.access_token,
expirationTime: Date.now() + (responseBody.expires_in * 1000),
};
}
示例4: e2e
async function e2e(filePath: string): Promise<void> {
console.log(`Running e2e for: ${filePath}`);
if (!fs.existsSync(filePath)) {
console.error("File not found");
throw Error("File not found");
}
const result = await request.post({
url: "https://wt-9017166451e5dc00461b648d19f5e8da-0.sandbox.auth0-extend.com/docx-validator",
formData: {
document: fs.createReadStream(filePath),
},
});
return result;
}
示例5: async
return async (req: express.Request, res: express.Response) => {
let encodedToken = res.locals.encodedToken;
let token = res.locals.token;
let tenantId = token["tid"];
let graphAccessToken: string;
// The version of the endpoint to use for OBO flow must match the one used to get the initial token
switch (token.ver) {
case "1.0":
{
// AAD v1 endpoint token
let tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/token`;
let params = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: encodedToken,
client_id: this.clientId,
client_secret: this.clientSecret,
resource: "https://graph.microsoft.com",
requested_token_use: "on_behalf_of",
scope: "openid",
} as any;
let tokenResponse = await request.post({ url: tokenEndpoint, form: params, json: true });
graphAccessToken = tokenResponse.access_token;
break;
}
case "2.0":
{
// AAD v2 endpoint token
let tokenEndpoint = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`;
let params = {
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
assertion: encodedToken,
client_id: this.clientId,
client_secret: this.clientSecret,
requested_token_use: "on_behalf_of",
scope: "https://graph.microsoft.com/User.Read",
} as any;
let tokenResponse = await request.post({ url: tokenEndpoint, form: params, json: true });
graphAccessToken = tokenResponse.access_token;
break;
}
default:
throw new Error(`Unsupported Azure AD endpoint version ${token.ver}`);
}
// The OBO grant flow can fail with error interaction_required if there are Conditional Access policies set.
// This example does not handle that. See https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols-oauth-on-behalf-of#error-response-example
// Get user profile from Graph
let options = {
url: "https://graph.microsoft.com/v1.0/me",
json: true,
headers: {
"Authorization": `Bearer ${graphAccessToken}`,
},
};
let profile = await request.get(options);
// Return profile as response
res.status(200).send(profile);
};