Python发get和post请求

get请求:

def getSolrdata(resume_id):
    url = 'http://10.18.99.92:8080/solr/resume_search/select?q=resume_id%3A' + str(resume_id) + '&wt=json&indent=true'
    req = urllib2.Request(url)
    try:
        resp = urllib2.urlopen(req)
    except urllib2.HTTPError, error:
        print "Cannot remove service instance!", error
        sys.exit(1)
    response = resp.read()
    return response


post请求:

def getRequestInfo(email,password):
    url = "http://192.168.6.80:8080/EmailResume/verify"
    body_value = {"email": email, "password": password}
    body_value = urllib.urlencode(body_value)
    request = urllib2.Request(url, body_value)
    # request.add_header(keys, headers[keys])
    result = urllib2.urlopen(request).read()
    return result

你可能感兴趣的:(Python)