网络编程

# from urllib.request import urlopen
# from urllib.parse import urlencode
# url = 'http://api.nnzhp.cn/api/user/login'
# d = {'username':'niuhanyang','passwd':'aA123456'}
# print(urlencode(d))
# # req = urlopen(url+'?'+urlencode(d))#get请求
# req = urlopen(url,urlencode(d).encode())#post请求
#
# print(req.read().decode())

import requests

#get请求
# url='http://img.xiumi.us/xmi/ua/17O3K/i/07efe34c090c4552078daea32d7ebc3a-sz_153856.jpg?x-oss-process=image/resize,w_1080/auto-orient,1/crop,x_0,y_0,w_720,h_587'
# d = {'stu_name':'矿泉水2'}
# r = requests.get(url,d)#发get请求

# print('r.json',r.json() ) #返回的是一个字典
# print('r.text',r.text)#返回的是一个字符串
# print('r.content',r.content)#返回的是bytes类型

# fw = open('sfsdfs.jpg','wb')
# fw.write(r.content)
# fw.close()

#post请求
# url='http://api.nnzhp.cn/api/user/login'
# data = {'username':'niuhanyang','passwd':'aA123456'}
# r = requests.post(url,data)
# print(r.json())
#传cookie、header
# url='https://qun.qq.com/cgi-bin/qun_mgr/get_friend_list'
# d = {'bkn': 1179529977}
# # cookie = {' tvfe_boss_uuid': '3a12ac91bd08d69c', ' pgv_pvid': '6758068840', ' pgv_pvi': '9797262336', ' RK': '1b4JBYR9aB', ' ptcz': '1056d2f367035d64d7b3e34b291bbe1d9c570081bf12a79eb1be0c574516c5fa', ' sd_userid': '35011558945432940', ' sd_cookie_crttime': '1558945432940', ' ptui_loginuin': '458727764@qq.com', ' o_cookie': '458727764', ' pac_uid': '1_458727764', ' pgv_si': 's2287503360', ' logout_page': '', ' uin': 'o0525586735', ' ptisp': 'cnc', ' skey': '@U8V4AaETp', ' p_uin': 'o0525586735', ' pt4_token': '4QVJFLPA7QXrB3Up6AvUUxz3PC1gAqygUoTinU1nC1g_', ' p_skey': 'GAX6P8UCl50rbNL6q-c6gok9l08LCe5pFysGs-y3PJM_', ' traceid': '3a69c2822e', ' ts_last': 'qun.qq.com/member.html', ' ts_uid': '6279869462'}
# header = {'cookie':'pgv_pvi=7661869056; RK=KRZhhBpcbw; ptcz=aaeb20d1e9557251855ed7cb94a52a5e4a0868151f2f4a99de4397e5d901cc3b; uin=o0511402865; ptisp=cnc; pgv_si=s8267628544; skey=@YGZhPn1yj; p_uin=o0511402865; pt4_token=iRNGXHEgTDZlLvIMwPRm4BJq3L0A*Z8xEMVpeTal*vs_; p_skey=pgPUHTMEhWz5fG0iZZ2O1BC1oqxg7R-iN8wpSlMOB*o_; traceid=38d9de77e4'}
# r = requests.post(url,d,headers = header)
# print(r.json())


# pgv_info=ssid=s1631281820;

#上传文件
# url= 'http://api.nnzhp.cn/api/file/file_upload'
# r = requests.post(url,files={'file':open('jjj.jpg','rb')})
# print(r.text)
url='http://api.nnzhp.cn/api/user/stu_info'
session = requests.session()

r1 = session.post('http://api.nnzhp.cn/api/user/login',
data={'username':'niuhanyang','passwd':'aA123456'})
print(r1.json())

#session 能自动管理cookie

# session.post('http://api.nnzhp.cn/api/user/pay')
#
# session.post('http://api.nnzhp.cn/api/user/order')

#1、登录接口 =》 cookie

#2、cookie
# 支付接口
#3、生成订单接口

#1、redis操作
#2、接口开发

posted on 2019-07-03 17:03  静思的技术博客  阅读(604)  评论(0编辑  收藏  举报

导航