import urllib.request import urllib.parse import http.client # method one data=urllib.parse.urlencode({'name':'posttest'}) headers={"Content-type":"application/x-www-form-urlencoded","Accept":"text/plain"} httpClient=http.client.HTTPConnection('localhost') httpClient.request("POST",'/1.php',data,headers) response=httpClient.getresponse() print(response.read().decode('utf-8')) # method two data=urllib.parse.urlencode({'name':'posttest123'}).encode('utf-8') request=urllib.request.Request('http://localhost/1.php',data=data,method="POST") response=urllib.request.urlopen(request) print(response.read().decode('utf-8'))