python urllib2 发起http请求post


使用urllib2发起post请求

 

def GetCsspToken():
    data = json.dumps({"userName":"wenbin", "password":"passwd"})
    try:
        req  = urllib2.Request('http:9.123.127.9/api/system/login', data, {'Content-Type':'application/json'})
        f = urllib2.urlopen(req)
        response = f.read()
        f.close()
    except urllib2.URLError, e:
        print e
    try:
        return json.loads(response)["entity"]["tokenId"]
    except:
        return ""

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM