【问题标题】:How to handle get completed POST request if 100:Continue in Express.js?如果 100:在 Express.js 中继续,如何处理完成的 POST 请求?
【发布时间】:2012-09-19 14:03:48
【问题描述】:

我要发布一个相对较大 (50K) 的文本文件:

curl -H "Content-Type:text/plain"  -d @system.log http://localhost:8888/

使用代理进行测试,我可以看到文件的全部内容正在发布。

但是 Express.JS 在标题中看到 100:Continue 和空白正文。我有:

app.use(express.bodyParser());

启用,顺便说一句。以下是标题:

{ 'user-agent': 'curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5',
  host: 'localhost:8888',
  accept: '*/*',
  'content-type': 'text/plain',
  'content-length': '55909',
  expect: '100-continue' }

req.body 为空:

{}

如何查看 Express.JS 中发布的所有数据?

【问题讨论】:

    标签: node.js http-headers express


    【解决方案1】:

    我的猜测是节点会根据node http module docs 自动发送100-continue 响应(假设您使用的是足够新的节点版本)。我猜正在发生的只是text/plain 内容类型不是bodyParser 可以解析为其他内容的格式(与json 或www-form-urlencoded 不同)。因此,您可以从标准的 data 事件中获取数据,该请求将为它读取的每个数据块发出该事件。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多