• 网络编程


    网络编程:实质是发送http请求。

    # from urllib.request import urlopen
    # from urllib.parse import urlencode
    # url='http://www.nnzhp.cn'
    # res=urlopen(url)
    # print(res.read().decode())
    # url='http://118.24.3.40/api/user/login'
    # res=urlopen(url)
    # print(res.read().decode())
    # data={'username':'niuhanyang','passwd':'aA123456'}
    # # print(urlencode(data))
    # res=urlopen(url,urlencode(data).encode())
    # print(res.read().decode())

    # import requests,json
    # url1='http://118.24.3.40/api/user/stu_info'
    # url='http://www.nnzhp.cn'
    # res=requests.get(url)
    # print(res.text)
    # print(type(res.text))
    # print(res.json())
    # res=requests.get(url1,params={'stu_name':'小黑'})

    # import requests,json
    # url='http://118.24.3.40/api/user/login'
    # data={'username':'niuhanyang','passwd':'aA123456'}
    # res=requests.post(url,data=data)
    # print(res.json())

    # import requests,json
    # url2='http://118.24.3.40/api/user/add_stu'
    # data={
    # "name":"requests_name",
    # "grade":"天蝎座",
    # "phone":"17722510123",
    # "sex":"男",
    # "age":28,
    # "addr":"河南省金静安嘉"
    # }
    # res=requests.post(url2,json=data)#入参是json类型的
    # print(res.json())


    # import requests,json
    # # url1='http://118.24.3.40/api/user/stu_info'
    # url='http://118.24.3.40/api/user/login'
    # # url='http://www.nnzhp.cn'
    # res=requests.get(url)
    # print(res.json())
    # # res=requests.get(url1,params={'stu_name':'小黑'})

    # import requests,json
    # url3='http://118.24.3.40/api/user/gold_add'
    # data={
    # "stu_id":"1111",
    # "gold":200
    # }
    # cookie={'niuhangyang':'abd9a0995f89787978979877887'}
    # res=requests.post(url3,json=data,cookie=cookie)#入参是json类型的,入参中含有cookie
    # print(res.json())


    # import requests,json
    # url3='http://118.24.3.40/api/user/all_stu'
    # header={'Referer':'http://api.nnzhp.cn/'}
    # res=requests.post(url3,headers=header)#入参是json类型的,入参中含有header
    # print(res.json())#返回的都是字典

    # import requests,json
    # url5='http://api.nnzhp.cn/'
    # res=requests.get(url5)
    # print(res.text)#返回的都是字符串

    # import requests
    # url6='http://qiniuuwmp3.changba.com/1108561083.mp3'
    # res=requests.get(url6)
    # print(res.content)#返回的就是二进制的
    # with open('魔鬼中的天使.mp3','wb') as fw:
    # fw.write(res.content)


    # import requests
    # url7="http://29e5534ea20a8.cdn.sohucs.com/c_zoom,h_200/c_cut,x_0,y_17,w_724,h_482/os/news/7f77740c54d213023faef7fa969dcb16.jpg"
    # res=requests.get(url7,verify=False)#如果是https要加上verify
    # res=requests.get(url7)
    # print(res.content)
    # with open('tu.jpg','wb') as fw:
    # fw.write(res.content)
    #
    #
    # print(res.content)#用来下载文件用的,返回的是二进制
    # print(res.json())#必须返回的是json才可以用
    # print(res.headers)#获取到返回的所有header
    # print(res.cookies)#获取到返回的所有的cookie
    # print(res.text)#下载文件不行,返回的是字符串

    #上传文件
    import requests,json
    url3='http://118.24.3.40/api/file/file_upload'
    data={'file':open('魔鬼中的天使.mp3','rb')}
    res=requests.get(url3)
    print(res.json())#返回的都是字典
  • 相关阅读:
    2019-8-31-C#-标准性能测试高级用法
    2018-8-29-Roslyn-通过-Target-修改编译的文件
    2018-8-29-Roslyn-通过-Target-修改编译的文件
    2018-2-13-图论-Warshall-和Floyd-矩阵传递闭包
    2018-2-13-图论-Warshall-和Floyd-矩阵传递闭包
    2019-10-26-Inno-Setup-安装包脚本-Run-的-Flags-标记
    netfilter
    mmap内存映射
    vim替换字符串
    vim环境配置
  • 原文地址:https://www.cnblogs.com/pengwa1226/p/9807870.html
Copyright © 2020-2023  润新知