ruby服务器没有收到PHP卷曲帖子

时间:2013-04-23 13:38:59

标签: php ruby post httprequest tcpserver

我有一个用TCPServer实现的简单ruby服务器,我需要通过运行PHP的其他服务器的POST请求来调用它。当我在终端中执行cURL或在浏览器中访问cURL时,ruby服务器会回复,但不会在从PHP服务器通过cURL调用时回复。我也试过调用fopen / stream_get_contents,但也没用。此外,cURL在PHP服务器上与其他应用程序一起工作正常......

这是我的PHP函数:

<?php
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'RUBY_SERVER_IP:RUBY_SERVER_PORT');
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, 'test=test');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);

$updates = curl_exec($curl_handle);
$output = curl_getinfo($curl_handle);
print_r($output);

curl_close($curl_handle);
?>

这是Ruby服务器:

require "socket"

server = TCPServer.new(80)

loop {
    client = server.accept
    response = "<html>Got it</html>"
    headers = ["HTTP/1.1 200 OK",
             "Server: Ruby",
             "Content-Type: text/html; charset=iso-8859-1",
             "Content-Length: #{response.length}\r\n\r\n"].join("\r\n")
    client.puts headers
    client.puts response
    client.close
}

任何想法为什么它不起作用? 非常感谢!

0 个答案:

没有答案