【发布时间】:2011-06-01 07:17:56
【问题描述】:
我正在尝试弄清楚如何将 pycurl“POST”发送到 REST 接口(在本例中为 Neo4j)。
我可以通过 CURL 做到这一点:
curl -HContent-Type:application/json -X POST -d '"http://localhost:7474/db/data/node/123"' http://localhost:7474/db/data/index/node/persons/name/peter
...但我无法弄清楚如何使用 CURL 选项进行翻译。这是我得到的最接近但失败了
data = "http://localhost:7474/db/data/node/123"
headers = {"Content-Type": "application/json"}
url_dir = "http://localhost:7474/db/data/index/node/persons/name/peter"
conn = pycurl.Curl()
c.setopt(pycurl.URL, url_dir)
c.setopt(pycurl.HTTPHEADER, headers)
我如何处理要传输的数据?
编辑:我所说的数据是指名为数据的变量。如何通过 pycurl 发送数据(-d 选项中包含的内容)。我已经尝试对其进行 urlencode 编码,但出现错误(显然,因为它的类型)。我试过 urllib.quote_plus() 但这导致 REST 服务出现 400 错误。我怀疑这是问题所在,因为我的 GET 工作正常。
【问题讨论】: