0
4

1 回答 1

2

所以首先,当使用 curl 处理动词时,你必须使用-X VERBNAME,例如,

~# curl -X POST http://httpbin.org/post
{
  "url": "http://httpbin.org/post",
  "data": "",
  "json": null,
  "args": {},
  "form": {},
  "origin": "127.0.0.1",
  "headers": {
    "User-Agent": "curl/7.19.6 (x86_64-unknown-linux-gnu) libcurl/7.19.6 OpenSSL/0.9.8n zlib/1.2.3 libidn/1.5",
    "Connection": "close",
    "Accept": "*/*",
    "Content-Length": "0",
    "Host": "httpbin.org"
  },
  "files": {}
}

其次,在提到参数的情况下,我会尝试这些变化:

import requests

# Variation 1
r = requests.post(url, data={'username': 'exampleuser'})

# Variation 2
r = requests.post(url, params={'username': 'exampleuser'})

# Followed by these lines
print r.status_code
print r.text

cURL 中的等效项应如下所示:

# Variation 1 equivalent
curl --data='username=exampleuser' -X POST http://httpbin.org/post

# Variation 2 equivalent
curl -X POST http://httpbin.org/post?username=exampleuser

我在第二行猜测这应该是一个application/x-www-form-urlencoded POST请求,所以两者的第一个变体应该可以工作。不过,我对画面一点也不熟悉,所以我不能保证两者都能奏效。

于 2013-05-16T23:10:07.290 回答