本文整理匯總了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);
};