[Python] HTTP POST

import http.client
import urllib.parse

connection = http.client.HTTPConnection('esquery.tku.edu.tw', 80, timeout=10)
connection.request(
    'POST',
    '/acad/query_result.asp',
    headers={
        'Host': 'esquery.tku.edu.tw',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Connection': 'close',
    },
    body=urllib.parse.urlencode({
        'func': 'go',
        'R1': 4,
        'weekdepts': 'ALL',
        'weekdept': 'ALL',
        'week': 1,
        'o1': '01',
        'o2': '14',
    })
)

with connection.getresponse() as response:
    print(response.status, response.reason)
    print(response.headers)
    data = response.read().decode('utf-8')
print(data)

Tested with Python 3.6.6

Show Comments