Open gudaoxuri opened 1 year ago
import { createServer, fetch } from 'http'; createServer((req, resp) => { req.on('data',async (body) => { if(req.url == '/wait'){ print("fetch..."); let response = await fetch('http://127.0.0.1:8001/echo', { method: 'POST', body: 'hello server' }) let result = await response.text() print("fetched:",result); resp.end(result) }else{ resp.end(body) } }) }).listen(8001,'0.0.0.0', () => { print('listen 8001 ...\n'); }) async function test_fetch() { let resp = await fetch('http://127.0.0.1:8001/wait', { method: 'POST', body: 'hello server' }) print('fetch client recv:', await resp.text()) print() } async function run_test() { await test_fetch() exit(0) } run_test()
Output after execution.
wait... fetched: hello server
No output fetch client recv:hello server
fetch client recv:hello server
So, after adding async/await operations to the http server, the request cannot get a response.
To return an empty response using CURL.
curl -d 'hello server' http://127.0.0.1:8001/wait -X POST curl: (52) Empty response from the server
Output after execution.
No output
fetch client recv:hello server
So, after adding async/await operations to the http server, the request cannot get a response.
To return an empty response using CURL.