python - How to send POST request? -


i found script online:

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 <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>' conn.close() 

but don't understand how use php or inside params variable or how use it. can please have little trying work?

if want handle http using python, highly recommend requests: http humans. post quickstart adapted question is:

>>> 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... >>>  

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -