POSTリクエストを送信するにはどうすればいいですか?質問する

POSTリクエストを送信するにはどうすればいいですか?質問する

このスクリプトをオンラインで見つけました:

import httplib, urllib
params = urllib.urlencode({'number': 12524, 'type': 'issue', 'action': 'show'})
headers = {"Content-type": "application/x-www-form-urlencoded",
            "Accept": "text/plain"}
conn = httplib.HTTPConnection("bugs.python.org")
conn.request("POST", "", params, headers)
response = conn.getresponse()
print response.status, response.reason
302 Found
data = response.read()
data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
conn.close()

しかし、PHP でこれをどのように使用するのか、params 変数内のすべてが何なのか、どのように使用するのかがわかりません。これを動作させるために少し手助けしていただけませんか?

ベストアンサー1

Pythonを使ってHTTPを扱いたいなら、ぜひお勧めしますリクエスト: 人間のための HTTPあなたの質問に適合した POST クイックスタートは次のとおりです。

>>> import requests
>>> r = requests.post("http://bugs.python.org", data={'number': '12524', 'type': 'issue', 'action': 'show'})
>>> print(r.status_code, r.reason)
200 OK
>>> print(r.text[:300] + '...')

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>
Issue 12524: change httplib docs POST example - Python tracker

</title>
<link rel="shortcut i...
>>> 

おすすめ記事