问题标签 [requestjs]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
410 浏览

node.js - 节点服务器出现错误 buffer.js:488 throw new Error('toString failed');

我们在 nodejs(服务器 A)上构建了一个应用程序,它使用 REST API 从另一个 nodejs 应用程序(服务器 B)获取数据。

同样,对于下载文件,服务器 A 在服务器 B 上发出请求,服务器 B 从 AWS S3 获取文件并将数据通过管道传输回服务器 A。

该系统运行良好,我们能够下载高达 1GB 的文件。

问题有时是服务器 A 崩溃并出现以下错误:

服务器 A 使用以下代码调用服务器 B:

我们不确定应用程序从哪里崩溃。请建议。

0 投票
1 回答
1046 浏览

node.js - Module Export callback function returns undefined

Hello: i am new to nodejs and mocha. I trying to use module.exports to return a value from a callback function. However, its returning undefined. For simple cases it works though. Please help.

Result

google.js

googleModule.js

0 投票
1 回答
536 浏览

node.js - NodeJS REST 土耳其字符,Socket 挂断

我的 REST 服务如下:

当我尝试在浏览器中获取服务时,我没有收到任何错误: http://localhost:8081/turkish-escape/ğ/

当我尝试使用我的 REST 客户端获得结果时,我遇到了一些土耳其特殊字符的问题。

客户端代码:

当我用 'ü' 调用客户端时,它工作正常,但如果我用 'ğ' 调用它,它会崩溃。这是调用和堆栈跟踪:

正如您从堆栈中看到的那样,它甚至从未到达 REST 服务的第一个 console.log 语句

0 投票
5 回答
85 浏览

javascript - 在运行时处理 50k 个网页(NodeJS)

我需要下载约 5 万个网页,从中获取一些数据并将其放入变量中。

我将每个请求包装到 Promise 中,然后将Promise.all()它们包装起来。我使用Request图书馆。

简化代码:

但是我收到ENFILE异常,这代表系统中打开的文件太多(在我的桌面上打开文件的最大数量为 2048)。

我知道 Promises 在创建时执行,但我无法解决这个问题。

也许还有其他方法可以做到这一点?感谢您的回复。

0 投票
2 回答
1835 浏览

php - 在使用 expressjs 重定向之前更改 POST 数据?

这基本上是我的代码:


这是这段代码需要做的:

当我进入file1.php并单击该Register按钮时,它应该将一个帖子请求发送回,file1.php其中包含{ test: "mytest" }来自的帖子标题http://localhost:1234file1.php对该发布请求执行某些操作并将响应发送回http://localhost:1234(在回调中request.post()),然后,它应该将 POST 标头更改为{ test: 1234 },重定向到file1.php并显示Array([test]=>1234) [Register button]在屏幕上。

问题是我无法让它在屏幕上显示该文本,似乎标题没有改变或者我没有很好地改变它们。我能做些什么?

0 投票
1 回答
97 浏览

node.js - 使用 ExpressJS 响应 GET 请求,然后在内部执行 RequestJS 请求

目前我只是在调用一个 API,特别是 Ticket Master Discovery API,它返回一个 JSON 对象就好了:

我想利用 ExpressJS 的“获取”来响应获取请求,然后在其中进行“请求”调用(如上所示)——这可能还是我的理解不正确?我已经继续阅读文档,并以最简单的形式理解每个文档,但我仍在苦苦挣扎。

谢谢

0 投票
1 回答
809 浏览

django - 如何在反应请求中发布带有数组字段的数据?

所以我使用来自https://github.com/request/request#forms的请求。在 tsx 文件中,我通过 id: id, text: string, array: number[].

这是一个带有 body 的 post 方法{id: id, text: text, array: array}。但是,来自 Django,当我request.data打印<QueryDict: {'text': ['hello'], 'id': ['12'], 'array[0]': ['51'], 'array[1]': ['52']}>. 这样,我无法通过调用来检索数组 ['51', '52] request.data.getlist('array')

我希望我的 request.data 采用这种格式:<QueryDict: {'text': ['hello'], 'id': ['12'], 'array': ['51', '52']}>因为 [51, 52] 是通过调用返回的request.data.getlist('array')

谢谢!

0 投票
1 回答
1145 浏览

node.js - Prevent express body-parser from removing body prior to request.pipe

I am trying to create a simple express middleware filter which should look at the POST body and determine if it should be piped to the correct server, or blocked. If I use body-parser it appears that I do get the req.body available to me, but it disappears from the request when I pipe the request to another external server.

The way I have tried to solve this is the following:

In urlHelper:

This seem to give me the req.body in my filter-method, but the body is consumed and is not received after it has been piped forward. I have tried multiple things, like req.emit('data', JSON.stringify(req.body)); and req.write(.., but it all seem to fail.

Is there a way for me to look at the request body before piping it further without deleting it? Or is there an inherit problem with my approach?

I have found multiple github issues and SO questions relating to this, but I haven't been successful in getting any of those approaches to work.:

https://github.com/expressjs/body-parser/issues/74

Writing express middleware to get raw request body before body-parser

https://github.com/expressjs/body-parser/issues/94

0 投票
1 回答
727 浏览

javascript - 通过字符串设置 Cookie

我想使用 requestjs 发出请求并在多个 javascript 文件甚至多个服务器之间共享 cookie。出于这个原因,我将 cookie 作为字符串存储在数据库中,并在需要时检索它们。

字符串看起来像这样,应该符合tough-cookie

如何让 requestjs 使用这些 cookie?该tough-cookie对象有一个fromJSON(string)我认为是我需要的方法。

所以我认为我应该能够做到

但这给出了错误TypeError: j.fromJSON is not a function

如何获取使用从数据库中获取的 cookie 字符串的请求?

0 投票
0 回答
1103 浏览

javascript - Express js 将多部分表单数据发布到外部 API

我有一个有角度的应用程序,并表示服务器是一个调用外部 API 的中间件

主要问题发生在 express 将数据发送到外部 API 时

我检查了表单是否正确生成,但外部 API 服务器给了我一个错误,说

“请求被拒绝,因为没有找到多部分边界”

请帮忙,或者有没有其他方法

更新

我稍微修改了代码以发送从浏览器获取的请求标头

所以现在我正在发送由浏览器设置的相同边界,但现在 java 服务器未检测到表单参数