- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我刚开始使用 TCPSockets。我只是想获取谷歌主页。这是我的代码:
require 'socket'
host = 'http://www.google.com'
port = 80
s = TCPSocket.open host, port
s.puts "GET / HTTP/1.1\r\n"
s.puts "Host: Firefox"
s.puts "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
s.puts "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
s.puts "\r\n"
while line = s.gets
puts line.chop
end
s.close
返回:
HTTP/1.1 302 Document has moved
Location: http://92.242.140.29/?nxdomain=http%3A%2F%2Ffirefox&AddInType=2&PlatformInfo=pbrgen
为什么?我的目标是获取谷歌主页的内容。谢谢
最佳答案
require 'socket'
host = 'www.google.com'
port = 80
s = TCPSocket.open host, port
s.puts "GET / HTTP/1.1\r\n"
s.puts "\r\n"
while line = s.gets
puts line.chop
end
s.close
此外,使用真正的 HTTP 客户端将使您的生活变得更加轻松。我喜欢Typhoeus .
关于Ruby TCPSocket/HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8649860/
我正在尝试编译 SFML 简单代码: #include #include #include #include using namespace std; int main(int argc, c
我正在尝试在作为客户端的笔记本电脑和作为服务器的个人电脑之间建立 TCP 连接。我的目标是使用服务器在两个 Android 设备之间发送消息。服务器有一个公共(public)IP地址。为了测试连接,我
这是我监听客户端 TCP 套接字的代码: def initialize @msg = '' @messages = Queue.new @socket = TCPSocket.
require 'socket' socket = TCPSocket.open('stream-api.betfair.com', '443') while line = socket.gets
我的线程 TCP 服务器出现问题。 我可以打开我的服务器,创建一个新的套接字,我可以通过套接字接收数据(我使用 readyRead() 信号然后使用 readLine() 读取,它工作正常。现在我想将
在 .NET 的多连接环境中接受套接字的正确方法是什么?即使负载很高,以下是否足够? while (true) { //block untill socket accepted var s
我刚开始使用 TCPSockets。我只是想获取谷歌主页。这是我的代码: require 'socket' host = 'http://www.google.com' port = 80 s = T
我有这个连接到 TCP 服务器(即 netcat)的 ruby 代码。它循环 20 次,并发送“ABCD”。如果我杀死 netcat,则需要两次循环迭代才能触发异常。在 netcat 被杀死后的第
我有一个连接到服务器的 ruby tcpsocket 客户端。 在发送数据之前如何检查套接字是否已连接? 我是否尝试“拯救”断开连接的 tcpsocket,重新连接然后重新发送?如果是这样,有没有
$ irb 1.9.3-p448 :001 > require 'socket' => true 1.9.3-p448 :002 > TCPSocket.new('www.example.com',
我正在使用 Ruby 测试使用套接字的 C# 网络应用程序。我用 @socket = TCPSocket.new(IP,PORT) 打开连接它有效 - 直到我要发送的文本超过 1024 个字符。然后
我有一个有界服务,它执行 TCP 套接字连接并重复发送一些数据。设备进入休眠模式后,线程停止,因此数据发送。我做错了什么? 据我所知,绑定(bind)到主 Activity 的服务必须是START_S
我用 C++ 开发了一个服务器,我想用 Ruby On Rails 开发一个接口(interface)。 所以我开始阅读http://ruby.railstutorial.org/ ,同时我开始寻找是
我写了一个 TCP 库,现在想支持 SSL。该库将连接/断开部分与数据流的处理分开。我能够插入一个流处理程序,它将传输和接收字节 block ,但它无法访问提供该数据的套接字。 所有使用 SslStr
我正在尝试在 Ruby 中创建自定义游戏服务器协议(protocol),但我不明白我可以/应该如何做一些事情: Q->1# 服务器使用 TCPServer/TCPSocket 向客户端发送一个数组。但
我正在尝试创建一个使用 TcpSocket 进行通信的 Firefox 插件。我已经使用以下代码通过 tcp 成功发送了消息: var tcpSocket = Cc["@mozilla.org/tcp
我正在尝试围绕大量使用 TCPSockets(具体来说是 IRC 机器人)的应用程序编写测试。在编写我的第一个类的测试时,我一直在做: #In the describe block before(:a
我正在使用 Rails 4.2.7 和 Ruby 2.3.0。我有通过 SOCKS 代理获取网页的代码 require "resolv-replace.rb" require 'open-uri' r
我有一个小型应用程序,用于连接(如聊天)。它捕获连接,从中获取登录名,然后监听数据并将其广播到每个连接,发送者除外。 问题是我不是一个非常高级的测试人员,也不知道如何测试。 # Handle each
我对 Ruby 不是很熟悉,所以找不到这个方法的文档。 像这样在 TCPSocket 对象上调用 each 时 require "socket" srv = TCPServer.new("localh
我是一名优秀的程序员,十分优秀!