我需要在 nodejs 中编写套接字,例如在 PHP 中。在 PHP 语言中,我执行以下操作:
$http_request = "POST $path HTTP/1.0\r\n";
$http_request .= "Host: $host\r\n";
$http_request .= "User-Agent: Picatcha/PHP\r\n";
$http_request .= "Content-Length: " . strlen($data) . "\r\n";
$http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
$http_request .= "\r\n";
$http_request .= $data;
$response = '';
$fs = @fsockopen($host, $port, $errno, $errstr, 10)
if (FALSE == $fs) {
die('Could not open socket');
}
fwrite($fs, $http_request);
如何在 nodejs 服务器中执行上述操作?