python client使用http post 到server端的代码

时间:2021-09-03 14:33:54 


import urllib, httplib 
import utils 
import json
       class User: 

        def __init__(self): 
            print 'a' 

        def login(self, imsi, ua): 
            print "==============user start login==================" 
            input = { 
                "method"       : "user.login", 
                "userName"     : "", 
                "userPass"     : "", 
            } 

            input["sig"] = utils.getSignature(input) 
            params = urllib.urlencode(input) 
            headers = { 
                "user-agent"  : ua, 
                "Appstore-clientType" : "android", 
                "Appstore-IMEI" : "123456789000000", 
                "Appstore-IMSI" : imsi 
            } 

            try: 
                connection = httplib.HTTPConnection(utils.API_HOST) 
                connection.request("POST", "/api", params, headers) 
                response = connection.getresponse().read() 
                #print "=========" + response 
                connection.close() 
            except Exception, e : 
                print "========" + str(e)     

            if "errorcode" in response or response is None: 
                return 

            results = json.loads(response)     

            return results["results"].encode("utf-8")
标签:http,post,server
0
投稿

猜你喜欢

  • python中arrow库用法大全

    2021-08-25 06:48:44
  • Python 条件判断的缩写方法

    2021-04-20 16:06:20
  • 日期垂直排列的两种技巧

    2009-08-28 12:38:00
  • python开发游戏的前期准备

    2022-01-06 12:58:01
  • 解决Python requests库编码 socks5代理的问题

    2023-01-29 13:27:28
  • asp dictionary对象的用法

    2011-04-14 11:09:00
  • oracle命令行删除与创建用户

    2008-01-02 17:01:00
  • python3中int(整型)的使用教程

    2021-12-29 19:51:31
  • Python Socketserver实现FTP文件上传下载代码实例

    2022-10-10 11:03:04
  • python内打印变量之%和f的实例

    2021-06-19 07:46:46
  • 解决pycharm下载库时出现Failed to install package的问题

    2021-07-30 14:15:49
  • 网站设计中的面包屑[译]

    2009-03-22 15:42:00
  • Python3.5装饰器典型案例分析

    2023-03-05 20:32:35
  • 用Python计算三角函数之atan()方法的使用

    2023-06-22 22:26:00
  • 详解使用Pytorch Geometric实现GraphSAGE模型

    2021-09-30 21:30:18
  • python geemap的安装步骤及环境配置

    2023-05-13 18:07:35
  • python生成n个元素的全组合方法

    2023-11-10 20:35:08
  • pytorch中F.avg_pool1d()和F.avg_pool2d()的使用操作

    2023-11-30 01:20:41
  • asp如何从数据库中调出个人档案?

    2009-11-15 20:02:00
  • python3 简单实现组合设计模式

    2023-06-12 19:15:50
  • asp之家 网络编程 m.aspxhome.com