帮助我将这个CURL转换为Rails中的Post方法 [英] Help me converting this CURL to a Post method in Rails

查看:146
本文介绍了帮助我将这个CURL转换为Rails中的Post方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一个XML发布到一个API,它返回一个XML。我成功地通过执行一个简单的CURL命令

  curlhttp://my.server.com/api/identity/ emails_from_ids
--proxy dvaic.snv.fex:80 -d< users>< id> 3434< / id>< / users&
-X POST -H'Content-Type:application / xml'-u admin:admin

上述命令成功执行。我想现在做同样使用Rails。怎么做?我经历了Net :: Http文档,但我不能从中得到很多解释。



谢谢

解决方案

这个怎么办?

  Net :: HTTP :: Proxy(dvaic.svn .fex,80,admin,admin)。start(my.server.com,80)do | http | 
response = http.post(/ api / identity / emails_from_ids,
< users>< id> 3434< / id>< / users>,
{ Content-Type=>application / xml})
#... response.body< ==使用XML响应
end
pre>

I am trying to post an XML to an API which returns me an XML. I successfully did that by executing a simple CURL command

curl "http://my.server.com/api/identity/emails_from_ids" 
--proxy dvaic.snv.fex:80 -d "<users><id>3434</id></users>" 
-X POST -H 'Content-Type: application/xml' -u admin:admin

The above command executes successfully. I would like to do the same using Rails now. How to do it? I went through the Net::Http documentation but I cannot decipher much from it.

Thanks

解决方案

And what about this one?

Net::HTTP::Proxy("dvaic.svn.fex", 80, "admin", "admin").start("my.server.com", 80) do |http|
  response = http.post("/api/identity/emails_from_ids", 
                       "<users><id>3434</id></users>", 
                       {"Content-Type" => "application/xml"})
  # ... response.body <== Response with XML
end

这篇关于帮助我将这个CURL转换为Rails中的Post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆