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


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

本文整理匯總了TypeScript中request-promise-native.post函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript post函數的具體用法?TypeScript post怎麽用?TypeScript post使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了post函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createPipe

 public async createPipe(): Promise<any> {
     const options = {
         uri: "https://api.bespoken.link/pipe",
         headers: {
             "x-access-token": "4772616365-46696f72656c6c61",
         },
         body: {
             // The secret key for the Skill
             uuid: this._secretKey,
             diagnosticsKey: null,
             endPoint: {
                 // The unique name/ID for the skill
                 name: this._id,
             },
             http: {
                 url: "https://proxy.bespoken.tools",
             },
             path: "/",
             pipeType: "HTTP",
             proxy: true,
         },
         json: true, // Automatically parses the JSON string in the response
         timeout: 30000
     };
     const response = await post(options);
     // Spokes creates a endPointID but not return the endPoint name
     response.endPoint = {
         name: this._id,
     };
     return response;
 }
開發者ID:bespoken,項目名稱:bst,代碼行數:31,代碼來源:spokes.ts

示例2: register

 async register(params) {
   const { payload } = params;
   // allow you to overload the client's baseUrl
   const { baseUrl = this.baseUrl } = payload;
   const url = `${baseUrl}/wallet`;
   const signature = this.sign({ method: 'POST', url, payload });
   return request.post(url, {
     headers: { 'x-signature': signature },
     body: payload,
     json: true
   });
 }
開發者ID:bitpay,項目名稱:bitcore,代碼行數:12,代碼來源:client.ts

示例3: importAddresses

  async importAddresses(params) {
    const { payload, pubKey } = params;
    const url = `${this.baseUrl}/wallet/${pubKey}`;

    console.log('addAddresses:', url, payload); // TODO
    const signature = this.sign({ method: 'POST', url, payload });
    const h = { 'x-signature': signature };
    return request.post(url, {
      headers: h,
      body: payload,
      json: true
    });
  }
開發者ID:bitpay,項目名稱:bitcore,代碼行數:13,代碼來源:client.ts

示例4: createDashboardSource

 public async createDashboardSource(id: string, secretKey: string) {
     const options = {
         uri: "https://source-api.bespoken.tools/v1/createSource",
         headers: {
         },
         body: {
             source: {
                 id,
                 secretKey,
                 name: id,
                 liveDebug: true,
             },
         },
         json: true,
         timeout: 30000
     };
     return post(options);
 }
開發者ID:bespoken,項目名稱:bst,代碼行數:18,代碼來源:source-name-generator.ts

示例5:

rpn.post({ url, oauth }, (e, r, body) => {
  // Ideally, you would take the body in the response
  // and construct a URL that a user clicks on (like a sign in button).
  // The verifier is only available in the response after a user has
  // verified with twitter that they are authorizing your app.

  // step 2
  let req_data = qs.parse(body);
  let uri = 'https://api.twitter.com/oauth/authenticate'
    + '?' + qs.stringify({ oauth_token: req_data.oauth_token });
  // redirect the user to the authorize uri

  // step 3
  // after the user is redirected back to your server
  let auth_data: any = qs.parse(body);
  let oauth = {
    consumer_key: CONSUMER_KEY,
    consumer_secret: CONSUMER_SECRET,
    token: auth_data.oauth_token,
    token_secret: req_data.oauth_token_secret,
    verifier: auth_data.oauth_verifier,
  };
  url = 'https://api.twitter.com/oauth/access_token';

  rpn.post({ url, oauth }, (e, r, body) => {
    // ready to make signed requests on behalf of the user
    let perm_data: any = qs.parse(body);
    let oauth = {
      consumer_key: CONSUMER_KEY,
      consumer_secret: CONSUMER_SECRET,
      token: perm_data.oauth_token,
      token_secret: perm_data.oauth_token_secret,
    };

    url = 'https://api.twitter.com/1.1/users/show.json';
    let query = {
      screen_name: perm_data.screen_name,
      user_id: perm_data.user_id
    };
    rpn.get({ url, oauth, qs: query, json: true }, (e, r, user) => {
      console.log(user);
    });
  });
});
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:44,代碼來源:request-promise-native-tests.ts

示例6: create

	async function create (folder: IAlbumFolder = null): Promise<IAlbumFile> {
		const albumFile = await AlbumFile.create({
			app: appId !== null ? appId : null,
			user: userId,
			folder: folder ? folder.id : null,
			dataSize: size,
			mimeType: mimetype,
			name: fileName,
			serverPath: null,
			hash: hash
		}) as IAlbumFile;
		try {
			const path = await request.post({
				url: `http://${config.fileServer.host}/register`,
				formData: {
					'file-id': albumFile.id,
					'passkey': config.fileServer.passkey,
					file: {
						value: file,
						options: {
							filename: fileName
						}
					}
				}
			});
			albumFile.serverPath = path;
			// 畫像だった場合幅と高さを取得してプロパティに保存しておく
			if (/^image\/.*$/.test(mimetype)) {
				const properties = await getPictureProperty(file, fileName);
				if (properties) {
					albumFile.properties = properties;
				}
			}
			await albumFile.save();
			return albumFile;
		} catch (e) {
			// remove temporary document
			await albumFile.remove();
			if (e instanceof StatusCodeError) {
				throw e.message;
			}
			throw e;
		}
	}
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:44,代碼來源:add-file-to-album.ts

示例7: broadcast

 async broadcast(params) {
   const { payload } = params;
   const url = `${this.baseUrl}/tx/send`;
   console.log('[client.js.113:url:]', url); // TODO
   return request.post(url, { body: payload, json: true });
 }
開發者ID:bitpay,項目名稱:bitcore,代碼行數:6,代碼來源:client.ts

示例8: Buffer

    x.pipe(resp);
  }
});

declare const resp: http.ServerResponse;
declare const req: rpn.RequestPromise;
req.pipe(rpn('http://mysite.com/doodle.png')).pipe(resp);

const r = rpn;
http.createServer((req, resp) => {
  if (req.url === '/doodle.png') {
    r.get('http://google.com/doodle.png').pipe(resp);
  }
});

rpn.post('http://service.com/upload', { form: { key: 'value' } });
// or
rpn.post('http://service.com/upload').form({ key: 'value' });
// or
rpn.post({ url: 'http://service.com/upload', form: { key: 'value' } }, (err, httpResponse, body) => { /* ... */ });

const data = {
  // Pass a simple key-value pair
  my_field: 'my_value',
  // Pass data via Buffers
  my_buffer: new Buffer([1, 2, 3]),
  // Pass data via Streams
  my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
  // Pass multiple values /w an Array
  attachments: [
    fs.createReadStream(__dirname + '/attachment1.jpg'),
開發者ID:enlight,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:request-promise-native-tests.ts

示例9: main

async function main() {
    // Ensure that the database exists.

    let database = await initializeDatabase();

    // Retrieve the main page.

    console.log(`Retrieving page: ${DevelopmentApplicationsUrl}`);
    let body = await request({ url: DevelopmentApplicationsUrl });
    let $ = cheerio.load(body);

    // Examine the HTML to determine how many pages need to be retrieved.

    let pageCount = Math.max(1, $("tr.pagerRow td").length - 1);
    let eventValidation = $("input[name='__EVENTVALIDATION']").val();
    let viewState = $("input[name='__VIEWSTATE']").val();

    if (pageCount === 1)
        console.log(`There is ${pageCount} page to parse.`)
    else
        console.log(`There are at least ${pageCount} pages to parse.`)

    // Process the text from each page.

    for (let pageIndex = 1; pageIndex <= 50; pageIndex++) {  // as a safety precaution enforce a hard limit of 50 pages
        console.log(`Parsing page ${pageIndex}.`);

        // Retrieve a subsequent page.

        if (pageIndex >= 2) {
            try {
                let body = await request.post({
                    url: DevelopmentApplicationsUrl,
                    headers: { "Content-Type": "application/x-www-form-urlencoded" },
                    form: {
                        __EVENTARGUMENT: `Page$${pageIndex}`,
                        __EVENTTARGET: "ctl00$Content$cusResultsGrid$repWebGrid$ctl00$grdWebGridTabularView",
                        __EVENTVALIDATION: eventValidation,
                        __VIEWSTATE: viewState
                }});
                $ = cheerio.load(body);
                eventValidation = $("input[name='__EVENTVALIDATION']").val();
                viewState = $("input[name='__VIEWSTATE']").val();
            } catch (ex) {
                console.log(`Reached the last page: ${ex.message}`);
                break;
            }
        }

        // Use cheerio to find all development applications listed in the current page.

        for (let element of $("table.grid tr.normalRow, table.grid tr.alternateRow").get()) {
            let row = $(element).children("td").get().map(cell => $(cell).text().trim());
            if (row.length < 4)
                continue;

            let applicationNumber = row[0];
            let receivedDate = moment(row[1], "D/MM/YYYY", true);  // allows the leading zero of the day to be omitted
            let description = row[2];
            let address = row[3];

            // Check for a valid application number and a non-empty address.

            if (!/^[0-9]{3}\/[0-9]{1,5}\/[0-9]{2}$/.test(applicationNumber) || address === "")
                continue;
    
            await insertRow(database, {
                applicationNumber: applicationNumber,
                address: address,
                description: ((description === "") ? "No description provided" : description),
                informationUrl: DevelopmentApplicationUrl.replace(/\{0\}/g, applicationNumber),
                commentUrl: CommentUrl,
                scrapeDate: moment().format("YYYY-MM-DD"),
                receivedDate: receivedDate.isValid ? receivedDate.format("YYYY-MM-DD") : ""
            });
        }
    }
}
開發者ID:planningalerts-scrapers,項目名稱:city_of_charles_sturt,代碼行數:78,代碼來源:scraper.ts


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