我正在查看问题'http client'
我做了以下通过2/3测试的解决方案:
request = require 'request'
#Generate a read/writable stream piping into the outbuff
myRequest = request.post("http://localhost:8099").pipe(process.stdout)
process.stdin.pipe(myRequest)
...出现以下错误:
operator: equal
expected:
'azzwcc\njup\nvccvwcddun\nmukp\nikeos.\nPaps\'w\nheghuuyuuv\nwu\nbzcawcsenvzm\nouggkneoasc\n'
actual:
'allsee\nfor\ndeedsetton\nyour\nquick.\nTark\'s\nbimboowood\nso\npleasekindly\ncommunicake\n'
但是,当我按此顺序管道输出时,它工作正常。
request = require 'request'
#Generate a read/writable stream piping into the outbuff
myRequest = request.post("http://localhost:8099")
process.stdin.pipe(myRequest).pipe(process.stdout)
这两种解决方案不应该相同吗?我在这里错过了什么?
答案 0 :(得分:1)
In the first example, you're passing the http response to stdout (but never writing to the request stream). Then you're passing input from stdin directly to stdout. So you have two streams writing to stdout. The resulting situation looks something like:
HTTP RESPONSE ----- | v STDIN -------> STDOUT
In the second example, you have input from stdin passed to the request stream and the response from that request passed to stdout. The resulting situation looks something like:
STDIN ----> HTTP REQUEST/RESPONSE ----> STDOUT