【问题标题】:how to send a post request and get the response in ruby如何发送发布请求并在 ruby​​ 中获取响应
【发布时间】:2010-07-22 09:53:33
【问题描述】:

如何发送 post 请求并在 ruby​​ 中获取响应

请求是,

name=$name_val

网址是http://example.com/a/2

我如何在 python 或 ruby​​ 中做到这一点?

【问题讨论】:

  • 您的一些问题不太明确,但this one 肯定有一个很好的答案,您应该点击答案旁边的勾号来接受。

标签: python ruby http


【解决方案1】:

在 python 中执行此操作:

import urllib
data = urllib.urlencode({
   "fieldName1" : "Val1", 
   "fieldName2" : "Val2", 
   "fieldName3" : "Val3"
})
f = urllib.urlopen("http://example.com/a/2", data)
html = f.read() # this is the response

【讨论】:

  • fieldName 是帖子名称,例如。发布后,它将数据发送到此 url example.com/a/2 然后 html = f.read() 返回如果您通过浏览器执行此操作将显示的 html 页面的内容。如果您在此页面上没有任何内容,那么您将不会得到任何回报。
猜你喜欢
  • 2023-02-01
  • 2011-12-21
  • 1970-01-01
  • 2011-07-06
  • 1970-01-01
  • 2019-02-23
  • 2020-10-05
  • 2021-11-06
  • 1970-01-01
相关资源
最近更新 更多