Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

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

But I don't understand how to use it with PHP or what everything inside the params variable is or how to use it. Can I please have a little help with trying to get this to work?

1 Answer

0 votes
by (106k points)

To send the post request you can use the below-mentioned code:-

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

>>>

Related questions

0 votes
1 answer
asked Oct 9, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 24, 2019 in Java by Nigam (4k points)

Browse Categories

...