import Cookie
import urllib
import httplib

def generateCookieString(aDict):
    str = [key+'='+data for key,data in aDict.items()]
    str = '; '.join(str)
    return str

def getResponse(host="", port=80, webpage="", method="GET", paramDict=None, cookieDict=None):

    header = {"Content-Type":"application/x-www-form-urlencoded",
    "Accept":"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*"}
    if cookieDict:
        print "encode cookie : " , urllib.urlencode(cookieDict)
        header['Cookie'] = generateCookieString(cookieDict)

    params=urllib.urlencode(paramDict)
    print "param : " , params

    conn = httplib.HTTPConnection(host, )
    conn.request(method, webpage, params, header)
    response = conn.getresponse()
    print response.status, response.reason

    data = response.read()
    conn.close()

    httpData= {}
    httpData['response'] = data
    httpData['cookie'] = response.getheader('Set-Cookie')
    httpData['msg'] = response.msg

    return httpData

def printResponse(aStr):
    print "------------------------- response start ------------------------------"
    print aStr
    print "------------------------- response end ------------------------------"

ef zeropageCookieTest():
    cookie = {"id":"1002"}
    params = {"gg":"ff"}
    httpData = getResponse(host="zeropage.org", webpage="/~reset/testing.php", method='GET', paramDict=params, cookieDict=cookie)
    print "return cookie : ", httpData['cookie']
    printResponse(httpData['response'])
    printResponse(httpData['msg'])

if __name__=="__main__":
    zeropageCookieTest()