惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
雷峰网
雷峰网
月光博客
月光博客
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
美团技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
A
Arctic Wolf
Latest news
Latest news
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
F
Fortinet All Blogs
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
Help Net Security
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 【当耐特】
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
H
Help Net Security
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog

博客园 - Tachikoma

Android 使用 Ksoap2 出现的低级错误... - Tachikoma Cygwin中通过RJB在Ruby下调用ICTCLAS(JAVA) ICTCLAS4J 的编译脚本 Ruby Sandbox 实现运行客户代码 - Tachikoma Ruby在使用MongoDB时,对Cursor的重新包装 ruby 下使用 ICTCLAS(JAVA) RJB 在windows下的一些安装事项 Ruby手工测试正确,rcov测试失败的解决 在dell dimension 5150 上安装 leopard 手记 Rails测试中清空数据表/载入空fixtures RDoc 解决同名module 与 Class的问题 C 实用的 e-editor 的bundle Best of Ruby Quiz - Animal Quiz Best of Ruby Quiz - GEDCOM Parser Best of Ruby Quiz - MadLib - Tachikoma 使用selenium-on-rails的一些讨论 3]assertXpathCount的使用 使用selenium-on-rails的一些讨论 2]清理缓存 - Tachikoma - 博客园 使用selenium-on-rails的一些讨论 [0,1] 关于 rails ActiveRecord 属性 以及 foreign_key 不直接用数据库项目 时的一些讨论
用Ruby实现 Web Service Server ,并用Ruby发送 HTTP请求 Web Service
Tachikoma · 2010-07-13 · via 博客园 - Tachikoma

因为项目需要,搭建一个最简单的web service Server,并用Ruby发送HTTP请求 Web Service

1. 首先先搭建一个Server , 实现一个简单的加法

require 'soap/rpc/standaloneServer'

class AddClass
	def add(i,j)
		return i.to_i + j.to_i
	end
end

class AddServer < SOAP::RPC::StandaloneServer
	def on_init
		add = AddClass.new
		add_method(add , 'add' , 'a' , 'b')		
	end
end

server = AddServer.new('hello' , 'namespace' , '0.0.0.0' , 2000)
trap('INT'){ server.shutdown }
server.level=SOAP::RPC::StandaloneServer::DEBUG
server.start

web service 名空间为namespace,地址为 localhost:2000,并输出DEBUG级别的信息

2. 用Ruby,发送HTTP POST请求,调用Web service

require 'net/http'
require 'uri'

req_headers= {
  'Content-Type' => 'text/xml; charset=utf-8',
  'SOAPAction' => '"http://localhost:2000/add#add"',
}

req_body = <<EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <add xmlns="namespace">
      <i>100</i>
      <j>1</j>
    </add>
  </soap:Body>
</soap:Envelope>
EOF

http = Net::HTTP.new('localhost' , 2000)
http.set_debug_output $stdout
res = http.request_post("/add" , req_body , req_headers)
puts res.body

很简单,就是手动制造出 HTTP POST请求Header 和 Body,Body中为请求的xml

都是从别人的代码中拼凑出来,记下来备查