http和webservice接口测试有什么区别?

webservice的基础组成是http+xml

三要素:soap传输协议,uddi,wsdl(webservice描述语言xml格式)

优点:跨平台,跨程序

缺点:xml格式,传输和解析耗费资源大

一。wsdl接口怎样使用python测试

官网文档地址:https://fedorahosted.org/suds/wiki/Documentation

1.什么是wsdl接口,本质是xml,框架很多比如cxf

2.python怎样调用wsdl接口,suds模块

入门例子,了解下wsdl和suds的样子

查询ip归属地

>>> import suds
>>> url="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"
>>> client=suds.client.Client(url)
>>> print client

打印结果:描述的很清楚,包括seivice,port 和method,直接调用你需要的

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( IpAddressSearchWebService ) tns="http://WebXml.com.cn/"
Prefixes (1)
ns0 = "http://WebXml.com.cn/"
Ports (2):
(IpAddressSearchWebServiceSoap)
Methods (3):
getCountryCityByIp(xs:string theIpAddress, )
getGeoIPContext()
getVersionTime()
Types (1):
ArrayOfString
(IpAddressSearchWebServiceSoap12)
Methods (3):
getCountryCityByIp(xs:string theIpAddress, )
getGeoIPContext()
getVersionTime()
Types (1):
ArrayOfString

调用方法:

res=client.service['IpAddressSearchWebServiceSoap12'].getCountryCityByIp('8.8.8.8')
print res

返回结果:

(ArrayOfString){
string[] =
"8.8.8.8",
"美国 加利福尼亚州山景市谷歌公司DNS服务器",
}

2.如果wsdl比较复杂,比如有多个service和port,使用client.service[service][port].getBank(),

如果不指定,默认是第一service的第一个port的第一个method

下面的就可以写成这样
client.service['OtherBLZService']['soap'].getBank()
client.service[1][0].getBank()
Suds - version: 0.3.7 build: (beta) R550-20090820

Service (BLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType Service (OtherBLZService) tns="http://thomas-bayer.com/blz/"
Prefixes (1)
ns0 = "http://thomas-bayer.com/blz/"
Ports (2):
(soap)
Methods (1):
getBank(xs:string blz, )
(soap12)
Methods (1):
getBank(xs:string blz, )
Types (5):
getBankType
getBankResponseType
getBankType
getBankResponseType
detailsType

复杂参数:

Suds - version: 0.3.3 build: (beta) R397-20081121

Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"
Prefixes (1):
ns0 = "http://test.server.enterprise.rhq.org/"
Ports (1):
(Soap)
Methods:
addPerson(Person person, )
echo(xs:string arg0, )
getList(xs:string str, xs:int length, )
getPercentBodyFat(xs:string name, xs:int height, xs:int weight)
getPersonByName(Name name, )
hello()
testExceptions()
testListArg(xs:string[] list, )
testVoid()
updatePerson(AnotherPerson person, name name, )
Types (23):
Person
Name
Phone
AnotherPerson

首先看下type里参数是什么样子的

c=suds.client.Client(url)
person=c.factory.create('Person')
print person
(Person)=
{
phone = []
age = NONE
name(Name) =
{
last = NONE
first = NONE
}
}

赋值有2中方法

1.基本:

phone = client.factory.create('Phone')
phone.npa = 202
phone.nxx = 555
phone.number = 1212
name = client.factory.create('Name')
name.first = 'Elmer'
name.last = 'Fudd'
person.name = name
person.age = 35
person.phone = [phone] json person{}
phone={'npa':202,'nxx':222,'number':'2222',}
name={'first':'li','last':'mi'} person['name']=name
person['age']=22
person['phone']=[phone,]

使用jmeter测试webservice接口,可查看我后来写的

https://www.cnblogs.com/xueli/p/9681526.html

二。http接口

使用requests

1.无参数get

 r = requests.get('http://httpbin.org/get')
print r.text {
"args": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, compress",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7"
},
"origin": "223.202.116.5",
"url": "http://httpbin.org/get"
}

有参数get

r = requests.get('http://www.so.com/s',params = {'q':'wwwww'})
print r.text

2.post,参数是字典

payload = {'name':'mmmmmmiiiiii','con':'hello'}
r = requests.post("http://httpbin.org/post", data=payload)
print r.text {
"args": {},
"data": "",
"files": {},
"form": {
"con": "hello",
"name": "mmmmmmiiiiii"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, compress",
"Content-Length": "",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "python-requests/2.2.1 CPython/2.7.5 Windows/7"
},
"json": null,
"origin": "223.202.116.5",
"url": "http://httpbin.org/post"
}

post,参数是json

>>> payload = {'name':'tttttlililililili','con':'hello'}

>>> import json

>>> r = requests.post('http://httpbin.org/post', data=json.dumps(payload))

定制headers,使用headers参数来传递

 headers = {'content-type': 'application/json'}
r = requests.post(url, data=json.dumps(payload), headers=headers)

最新文章

  1. 初学者--bootstrap(六)组件中的下拉菜单----在路上(10)
  2. 资源描述结构(Resource Description Framework,RDF)
  3. gitlab备份及迁移
  4. pythonchallenge 解谜 Level 0
  5. android studio中如何设置注释模板
  6. IndexOutOfBoundsException ArrayList 访问越界
  7. Android的Activity屏幕切换动画-左右滑动切换
  8. 第十五章:Android 调用WebService(.net平台)
  9. linux rdsktop 运程管理 windows
  10. Mysql存储过程总结
  11. selenium python 第一个脚本
  12. cocos2d-x触摸事件优先级的探究与实践
  13. 第一章 工欲善其事 其利润—Android SDK工具(2)
  14. Spring+SpringMVC+MyBatis深入学习及搭建(四)——MyBatis输入映射与输出映射
  15. MySQL主从复制的实现过程
  16. CSS3文本
  17. Vue 进阶之路(四)
  18. vue搭建app, M端项目流程
  19. Tomcat开启本地库(Apache Tomcat Native Library)支持
  20. 长沙IT二十年

热门文章

  1. linux 网卡问题 Device eth0 does not seem to be present,delaying initialization.
  2. iOS检测版本更新
  3. 对copy、mutableCopy理解
  4. Windows下QT Creator工程中添加文件夹
  5. mac brew mysql 启动之后报错
  6. c# 第一个实例 通哥
  7. SQL变量、Substring、charindex、case函数、去除重复
  8. html之页面元素印射
  9. C#如何获取物理网卡,虚拟网卡,以及无线网卡
  10. Three.js typescript definitely typed 文件