当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript needle.post函数代码示例

本文整理汇总了TypeScript中needle.post函数的典型用法代码示例。如果您正苦于以下问题:TypeScript post函数的具体用法?TypeScript post怎么用?TypeScript post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了post函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Multipart

function Multipart() {
    const buffer = fs.readFileSync('/path/to/package.zip');

    const data = {
        zip_file: {
            buffer,
            filename: 'mypackage.zip',
            content_type: 'application/octet-stream'
        }
    };

    // using promises
    needle('post', 'http://somewhere.com/over/the/rainbow', data, { multipart: true })
        .then((resp) => {
            // if you see, when using buffers we need to pass the filename for the multipart body.
            // you can also pass a filename when using the file path method, in case you want to override
            // the default filename to be received on the other end.
        });

    // using callback
    needle.post('http://somewhere.com/over/the/rainbow', data, { multipart: true }, (err, resp, body) => {
        // if you see, when using buffers we need to pass the filename for the multipart body.
        // you can also pass a filename when using the file path method, in case you want to override
        // the default filename to be received on the other end.
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:26,代码来源:needle-tests.ts

示例2: API_post

function API_post() {
    var options = {
        headers: { 'X-Custom-Header': 'Bumbaway atuna' }
    };

    needle.post('https://my.app.com/endpoint', 'foo=bar', options, function (err, resp) {
        // you can pass params as a string or as an object.
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:9,代码来源:needle-tests.ts

示例3: FileUpload

function FileUpload() {
    var data = {
        foo: 'bar',
        image: { file: '/home/tomas/linux.png', content_type: 'image/png' }
    };

    needle.post('http://my.other.app.com', data, { multipart: true }, function(err, resp, body) {
        // needle will read the file and include it in the form-data as binary
    });
    needle.put('https://api.app.com/v2', fs.createReadStream('myfile.txt'), function(err, resp, body) {
        // stream content is uploaded verbatim
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:13,代码来源:needle-tests.ts

示例4: function

	inviteUserToSlack: function(user) {
		var url = 'https://' + sails.config.slack.communityName + '.slack.com/api/users.admin.invite?t=' + Date.now();
		var data = {
			email: user.email,
			channels: "C051QDDUU,C051QDJJN",
			first_name: user.username,
			token: sails.config.slack.token,
			set_active: true
		};
		Needle.post(url, data, function(err, resp) {
			if (err) PrettyError(err, "An error occurred while inviting a user to slack:")
		});
	}
开发者ID:ModMountain,项目名称:web-old,代码行数:13,代码来源:SlackService.ts

示例5: MultipartContentType

function MultipartContentType() {
    var data = {
        token: 'verysecret',
        payload: {
            value: JSON.stringify({ title: 'test', version: 1 }),
            content_type: 'application/json'
        }
    }

    needle.post('http://test.com/', data, { timeout: 5000, multipart: true }, function(err, resp, body) {
        // in this case, if the request takes more than 5 seconds
        // the callback will return a [Socket closed] error
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:14,代码来源:needle-tests.ts

示例6: API_post

function API_post() {
    const options = {
        headers: { 'X-Custom-Header': 'Bumbaway atuna' }
    };

    // using promises
    needle('post', 'https://my.app.com/endpoint', 'foo=bar', options)
        .then((resp) => {
            // you can pass params as a string or as an object.
        });

    // using callback
    needle.post('https://my.app.com/endpoint', 'foo=bar', options, (err, resp) => {
        // you can pass params as a string or as an object.
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:16,代码来源:needle-tests.ts

示例7: publishWebhook

function publishWebhook(message: Message, url: string) {
    const options = {
        json: true,
    };

    needle.post(url, message, options, (err, res) => {
        if (err) {
            return false;
        }

        if (res.body && res.body.error) {
            return false;
        }

        return true;
    });
}
开发者ID:lovett,项目名称:notifier,代码行数:17,代码来源:publish-message.ts

示例8: sendContactEmail

export function sendContactEmail(req, res) {
  const DOMAIN = 'sandbox587d48a9dc7c4ef696a3a149c2d9747d.mailgun.org';
  let KEY = 'key-998712bea03a50212c650813b823352f';
  let options = req.body;

  let recipient = (process.env.NODE_ENV !== 'production') ?
    'qiyen77@gmail.com' :
    ['proair@proairmarine.com','shiamary@proairmarine.com'];

  needle.post(`https://api:${KEY}@api.mailgun.net/v3/${DOMAIN}/messages`, {
    from: options.email,
    to: recipient,
    subject: `Email from ${options.name} titled: ${options.title}`,
    text: options.message,
  }, (err, response) => (err) ?
    res.status(200).json({ sent: false, data: err }) :
    res.status(200).json({ sent: true, data: response.body }));
}
开发者ID:kennyqiyenkan,项目名称:Proair-Web,代码行数:18,代码来源:api.ts

示例9: function

 }).then(function (transaction:Transaction) {
   Needle.post(transaction.paypalExecuteUrl, {
     payer_id: payerId
   }, function (err, resp) {
     if (err) {
       PrettyError(err, "An error occurred during Needle.post inside AddonsController.paypalCheckoutGET:");
       req.flash('error', "Something went wrong during PayPal checkout, please try again.");
       res.redirect('/addons/' + addonId)
     } else {
       Addon.findOne(addonId)
         .then(function (addon:Addon) {
           transaction.inProgress = false;
           req.user.sentTransactions.add(transaction);
           addon.author.receivedTransactions.add(transaction);
           // If the user bought a paid addon we need to track the purchase
           if (addon.price > 0) {
             req.user.purchases.add(addon);
           }
           if (transaction.couponCode !== undefined) addon.incrementCoupon(transaction.couponCode);
           addon.author.balance += amountToCharge;
           return [addon, req.user.save(), addon.author.save(), transaction.save()];
         }).spread(function (addon) {
           if (addon.price === 0) {
             NotificationService.sendUserNotification(addon.author, "MEDIUM", req.user.username + " donated $" + transaction.amount / 100 + " USD to your addon, '" + addon.name);
             req.flash('success', 'Donation success');
           } else {
             NotificationService.sendUserNotification(addon.author, "MEDIUM", req.user.username + " purchased your addon, '" + addon.name + "' for $" + transaction.amount / 100);
             req.flash('success', 'Purchase success');
           }
           FeeService.chargeFee(addon.author);
           res.redirect('/addons/' + addonId);
         }).catch(function () {
           PrettyError(err, "An error occurred during Addon.findOne inside AddonsController.paypalCheckoutGET:");
           req.flash('warning', "Something went wrong but your purchase succeeded. You may be contacted by support.");
           res.redirect('/addons/' + addonId)
         })
     }
   })
 }).catch(function (err) {
开发者ID:ModMountain,项目名称:web-old,代码行数:39,代码来源:AddonsController.ts

示例10: FileUpload

function FileUpload() {
    const data = {
        foo: 'bar',
        image: { file: '/home/tomas/linux.png', content_type: 'image/png' }
    };

    // using promises
    needle('post', 'http://my.other.app.com', data, { multipart: true })
        .then((resp) => {
            // needle will read the file and include it in the form-data as binary
        });
    needle('put', 'https://api.app.com/v2', fs.createReadStream('myfile.txt'))
        .then((resp) => {
            // stream content is uploaded verbatim
        });

    // using callback
    needle.post('http://my.other.app.com', data, { multipart: true }, (err, resp, body) => {
        // needle will read the file and include it in the form-data as binary
    });
    needle.put('https://api.app.com/v2', fs.createReadStream('myfile.txt'), (err, resp, body) => {
        // stream content is uploaded verbatim
    });
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:24,代码来源:needle-tests.ts


注:本文中的needle.post函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。