當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript request-promise.post函數代碼示例

本文整理匯總了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);
 }
開發者ID:EJayCheng,項目名稱:oPay-ts,代碼行數:36,代碼來源:oPay.ts

示例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;
   }
 }
開發者ID:duniter,項目名稱:duniter,代碼行數:14,代碼來源:contacter.ts

示例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),
        };
    }
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:16,代碼來源:LinkedInProvider.ts

示例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;
}
開發者ID:dolanmiu,項目名稱:docx,代碼行數:17,代碼來源:e2e.ts

示例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);
        };
開發者ID:billbliss,項目名稱:microsoft-teams-sample-auth-node,代碼行數:63,代碼來源:GetProfileFromGraph.ts


注:本文中的request-promise.post函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。