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)
  • 相关阅读:
    CSS基本
    Visual Basic相关图书推荐
    Docker相关图书推荐
    PASCAL相关图书推荐
    正则表达式相关图书推荐
    Go语言相关图书推荐
    F#相关图书推荐
    Ruby相关图书推荐
    PHP相关图书推荐
    Swift相关图书推荐
  • 原文地址:https://www.cnblogs.com/jpr-ok/p/10819132.html
Copyright © 2011-2022 走看看