我怎样才能让使用防爆preSS框架,AJAX请求? [英] How can I make AJAX requests using the Express framework?

查看:204
本文介绍了我怎样才能让使用防爆preSS框架,AJAX请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用防爆preSS发送AJAX请求。我运行code,看起来像下面这样:

I want to send AJAX requests using Express. I am running code that looks like the following:

var express = require('express');
var app = express();

app.get('/', function(req, res) {
   // here I would like to make an external
   // request to another server
});

app.listen(3000);

我将如何做到这一点?

How would I do this?

推荐答案

您不需要防爆preSS进行传出HTTP请求。使用本机模块是:

You don't need Express to make an outgoing HTTP request. Use the native module for that:

var http = require('http');

var options = {
  host: 'example.com',
  port: '80',
  path: '/path',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': post_data.length
  }
};

var req = http.request(options, function(res) {
  // response is here
});

// write the request parameters
req.write('post=data&is=specified&like=this');
req.end();

这篇关于我怎样才能让使用防爆preSS框架,AJAX请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆