相关疑难解决方法(0)

Node.js:通过unix socket发送GET请求

我是node.js的新手.我正在尝试使用unix socket设置客户端服务器连接,其中我的客户端请求将在node.js中,而后台运行的服务器将在其中.

客户端代码:

    var request = require('request');

    request('http://unix:/tmp/static0.sock:/volumes/list', function (error, response, body) {
        if (!error && response.statusCode == 200) {
            console.log(body)
        } else {
            console.log("In else part of the receiver" + response.statusCode + body)
        }
    }


})
Run Code Online (Sandbox Code Playgroud)

当我尝试与写入的服务器进行通信时,它显示了 HTTP error: 400 Bad Request: malformed Host header'

同样适用于:

curl -X GET --unix-socket /tmp/static0.sock http://:/volumes/list
Run Code Online (Sandbox Code Playgroud)

不确定我的请求有什么问题.我们需要发送标题吗?我期待JSON的回应.

javascript sockets go unix-socket node.js

7
推荐指数
1
解决办法
4484
查看次数

标签 统计

go ×1

javascript ×1

node.js ×1

sockets ×1

unix-socket ×1