http接口测试工作问题记录

1、接口测试返回值为excel表,如何测试?

get请求的接口,返回值为excel表。直接在浏览器访问get请求,会自动下载excel表。下载的excel表数据与数据库数据进行比对验证结果是否正确

如果浏览器访问接口下载excel没有权限如何解决?

a、https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js 打开该网页,复制代码;
b、把接口请求连接粘贴到浏览器,按F12,把步骤1的代码粘贴过来;
c、输入登录权限的代码(可以修改用户名密码)
$.ajax({url:"http://服务器IP:端口号/json/auth/login",type:"post",data:{'username':'XXXX', 'password':'XXX','new_password':"XXX|",'re_password':'XXX','code':1212},success:function(d){console.log(d);}});

2、接口请求的图片地址参数是需要通过base64转码的,如何填写参数?

可以使用python,需要在python中运行以下代码得到图片的转码信息

def file_encode(filename):
import base64
f = open(filename,'rb').read()
res = base64.b64encode(f).decode()
print(res)
file_encode(r'e:\timg.gif')    //本地图片路径

3、接口请求参数是时间戳,如何填写参数?

可以使用python的代码,需要将日期转换成时间戳,再输入到请求参数中

#coding:UTF-8
import time

dt = "2017-12-04 20:28:54"

#转换成时间数组
timeArray = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
#转换成时间戳
timestamp = time.mktime(timeArray)

print(timestamp)

原文地址:https://www.cnblogs.com/xiaojing2017/p/8005419.html