zoukankan      html  css  js  c++  java
  • Python接口测试-以&连接拼接字典数据(get中url请求数据)

    get请求的utl数据是这样的,例如:/banner/findBanner?bannerType=1&_=1556107073181

    '''
    1-banner图-banner/findBanner
    '''
    str1=parse.urlencode(data1)
    url1='{0}/banner/findBanner?bannerType=1&_=1556107073181'.format(yuming)
    headers ={'Content-Type':'application/json;charset=UTF-8',
              'Accept':'application/json, text/javascript, */*; q=0.01',
              'Referer':'{0}/'.format(yuming)}
    r=requests.get(url=url1,headers=headers)
    repones=r.text
    print('*'*100,'
    ','1-banner图-banner/findBanner','
    ','*'*100)
    print()
    print(r.status_code)
    print(r.text)

    如果参数比较多的话如何自动拼接呢

    from urllib import parse
    
    '''
    1-banner图-banner/findBanner
    '''
    data1={
        'bannerType':1,
        '_':1556107073181
    }
    str1=parse.urlencode(data1)
    url1='{0}/banner/findBanner?{1}'.format(yuming,str1)
    headers ={'Content-Type':'application/json;charset=UTF-8',
              'Accept':'application/json, text/javascript, */*; q=0.01',
              'Referer':'{0}/'.format(yuming)}
    r=requests.get(url=url1,headers=headers)
    repones=r.text
    print('*'*100,'
    ','1-banner图-banner/findBanner','
    ','*'*100)
    print()
    print(r.status_code)
    print(r.text)
  • 相关阅读:
    Eclipse 中使用 ctrl 无法追踪函数的问题
    AJAX跨域问题
    eclipse设置svn代理
    同步IO和异步IO
    阿里云配置redis
    Centos +django+nginx
    Centos 安装nginx
    django 给前端传递HTML内容
    django项目初探
    python邮件服务
  • 原文地址:https://www.cnblogs.com/jpr-ok/p/10819132.html
Copyright © 2011-2022 走看看