Tag: 请求

我的http请求有什么问题

我能够input我的url:192.168.1.132到我的浏览器,我得到正确的响应与“你好世界”,同样的事情,如果我做一个curl192.168.1.132 但如果我运行这个代码 var http = require('http'); var options = { host: 'http://192.168.1.132', path: '/' }; callback = function(response) { var str = ''; //another chunk of data has been recieved, so append it to `str` response.on('data', function (chunk) { str += chunk; }); //the whole response has been recieved, so we just print it out […]

如何查找表单参数的存储位置,并在请求中使用它们

我正在尝试使用Request和Cheerio为https://www.freelance.nl/opdrachten/zoeken提供数据,但是我遇到了发布search条件的问题。 在使用该站点时,我无法看到searchstring和所选类别在发送过程中的位置,以及我如何在请求中使用它们来自动执行来自我的节点应用程序的search。 基本上我希望能够发送不同的search条件使用请求,然后我可以刮我返回的HTML数据,我需要的。 到目前为止,我有这样的: request.post('https://www.freelance.nl/opdrachten/zoeken', { form: { key: 'value' } }, function (error, response, body) { if (!error && response.statusCode == 200) { console.log(body) } } ); 但是由于我无法看到表单数据在开发工具中的存储位置,我无法在“表单”对象中发送正确的值。 我很确定它是在请求有效负载,但我怎么从我的节点应用程序? 有没有更简单的方法来做到这一点? 我完全在浪费时间吗?

为什么在获取请求后,远程服务器响应在nodejs上不包含x-csrf-token?

我正在使用nodejs和请求插件( https://github.com/request/request )来创build代理。 路由一切正常,但我的代理服务器应该转发的其中一个服务器需要CSRF令牌。 问题是,正在发送提取请求,但服务器响应不包含x-csrf-token。 这似乎是请求插件是“swalling”这个字段。 我的意思是,这不是空的回应,不。 标题甚至不包含该字段。 我必须使用请求插件的原因。 所以切换插件是没有帮助的。 任何想法可以导致这个问题? 更新(示例代码) app.use(sIncoming, function (req, res, next) { options = { 'url': sDestination + req.url, 'ca': cas, 'jar': true,// enable cookies, 'strictSSL': true, 'headers': { accept: '*/*' } }; request(options, function (err, response, body) { if (err) onsole.error(err); else { if (typeof req.headers['x-csrf-token'] === "string") […]

节点中第二次请求延迟15秒

我有一个服务器需要发送多个http请求。 但是除第一个请求之外,每个请求都会触发一个15秒的延迟。 如果我从linux控制台,POSTman或Fiddler发送请求,它的工作很好,没有延迟,但我不能得到它从节点工作。 我已经尝试使用https.get() , request ,套接字,甚至在一个单独的文件分叉请求。 但延误还在。 服务器回复正确的Connection: close标题。 该服务器是一个nginx服务器。 从节点工作的唯一时间是如果我把我的请求在一个单独的脚本,只运行这个脚本。 这可能是有效的,因为节点在请求后退出并释放连接。 我曾尝试与agent: false ,我发送Connection: close服务器,但它为什么需要15秒钟closures,为什么不使用小提琴手或POSTMAN时发生这种情况? 编辑:添加代码。 这个代码在我第一次运行的时候运行的非常完美,但是如果我运行了两次或者更多的话,延迟就会出现。 这是导致延迟的第二个函数,第一个函数工作正常。 async.waterfall([ function(cb) { console.log('making first connection'); var post_data = querystring.stringify({ 'login' : username, 'password' : password }); var options = { hostname: 'hostname', port: 443, path: '/path', method: 'POST', agent: agent, pool: false, keepAlive: false, […]

request-promise不能被webpacked

所以我试图在客户端使用request-promise,并尝试使用webpack打包,但由于某些文件模块fs ,它不能打包到客户端。 有没有人偶然发现同样的问题并解决? 这是编译输出 ERROR in ./~/request-promise/~/request/lib/har.js Module not found: Error: Cannot resolve module 'fs' in /node_modules/request-promise/node_modules/request/lib @ ./~/request-promise/~/request/lib/har.js 3:9-22 ERROR in ./~/request-promise/~/request/~/forever-agent/index.js Module not found: Error: Cannot resolve module 'net' in /node_modules/request-promise/node_modules/request/node_modules/forever-agent @ ./~/request-promise/~/request/~/forever-agent/index.js 6:10-24 ERROR in ./~/request-promise/~/request/~/forever-agent/index.js Module not found: Error: Cannot resolve module 'tls' in /node_modules/request-promise/node_modules/request/node_modules/forever-agent @ ./~/request-promise/~/request/~/forever-agent/index.js 7:10-24 ERROR in ./~/request-promise/~/request/~/tough-cookie/lib/cookie.js […]

发送POST请求并通过Node.js获取数据

我一直在努力发送POST请求和使用Node.js获取数据 我一直在这样试用 var querystring = require('querystring'); var http = require('http'); var postData = querystring.stringify({ }); var options = { hostname: 'www.google.com', port: 80, path: '/', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': postData.length } }; var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); console.log('HEADERS: ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: […]

请求后获得400状态码使用节点JS Express

我有以下代码将文档发布到特定的位置。 一切都是正确的,但不知何故,我得到了400错误的请求。 有人可以build议为什么会这样。 以下是我的代码。 function storeDocuments(req, res, tokenKey, data) { var uniqueCode = getClientCode(req, res); var filePath = path.normalize(data.pdfURL); var boundaryKey = Math.floor(Math.random() * 1E16); var options = { method: 'POST', url: 'https://api.fundpress.io/docloader/adddocument', headers: { 'content-type': 'multipart/form-data; charset=utf-8; boundary=—' + boundaryKey, 'cache-control': 'no-cache', 'X-KSYS-TOKEN': tokenKey }, formData: { file: { value: fs.createReadStream(filePath), options: { filename: […]

AWS lambda内存消耗请求pipe道

我有一个Lambda函数,很简单: 'use strict'; var request = require('request'); var aws = require('aws-sdk'); var s3 = new aws.S3({ apiVersion: '2006-03-01' }); exports.handler = (event, context, callback) => { var stream = require('fs').createWriteStream('/tmp/tmpFile'); request .get(event.url) .pipe(stream); }; 但是,当我试图下载一个50MB的文件,我的function用完内存(使用:139,最大:128)。 我真的不明白,因为这个文件太小了。 你有一个想法,它可能来自哪里?

在完成加载/redirect后,擦除页面

有问题的网页: http://watch2gether.com/go#<link> 我需要能够完全加载并redirect到最终目的地后才能抓取此页面。 现在来详细说一下我的问题:我一直在用请求和cheerio来试图抓取页面,并且我已经成功地这样做了: var searchTerm = 'https://www.youtube.com/watch?v=link'; var url = 'https://www.watch2gether.com/go#' + searchTerm; request(url, function(err, resp, body){ $ = cheerio.load(body); links = $('link'); //use your CSS selector here $(links).each(function(i, link){ sleep.sleep(2); console.log($(link).text() + ':\n ' + $(link).attr('href')); }); }); 但是,它会返回页面实际加载前的每个href属性的值,并将其redirect到最终页面,所以它确实是在http://watch2gether.com/go#取代http://watch2gether.com/rooms/ 由于第二页只在第一页被请求之后被加载,所以我怎样才能让我的代码第二页而不是第一页呢?

节点请求库错误:getaddrinfo ENOTFOUND dns.js 26

我以连续的方式(每天多次请求一次)抓取网站,并且每次都使用asynchronous和请求节点模块。 我使用async eachLimit并行运行函数getPage(这里没有显示代码)。 但是,一旦在几千个查询中,我收到以下错误: Error: getaddrinfo ENOTFOUND 247sports.com 247sports.com:80 at errnoException (dns.js:26:10) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26) 即使我知道我通过它的url是有效的。 我发现有人使用http模块的解决scheme,并得到相同的错误,但似乎没有人使用请求模块得到这个。 我知道我的IP没有被阻止,因为我可以在错误之后立即访问网站。 我也知道我的用户代理不是问题,因为我旋转了用户代理列表,所有这些都是有效的。 我的猜测是问题在于请求库与节点http模块交互的地方。 不幸的是,我无法准确地重现问题,因为当我同时或连续推送大量请求时,它似乎只是被触发。 下面的函数代码是我的函数的样子: function getPage(){ var options = { url: "http://stackoverflow.com/", headers: { 'User-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20110506 Firefox/4.0.1' }; request(options, function(err, resp, body) { if (err){ throw err; return; } PagesScraped++; […]