Windows/mac环境上有很多接口测试的工具,如soapui、postman等,但这些工具在linux平台上使用起来相对不那么便捷。
有时候当我们要测试一些外部接口时,当本地无权调用测试路径时,需要将测试建立在linux平台,除了封装简单的请求代码进行实现外,可通过curl工具实现。
1、测试get请求
$ curl http://www.linuxidc.com/login.cgi?user=test001&password=123456
2、测试post请求
$ curl -d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi
3、xml格式post请求
接口如下:
请求方式:
方式一:发送磁盘上面的xml文件(推荐)
[plain] view plain copy
-
root [ /apps ]$ curl -X POST -H 'content-type: application/xml' -d @/apps/myxmlfile.txt http://172.19.219.xx:8081/csp/faq/actDiaUserInfo.action
ps:其中myxmlfile.txt为磁盘上面的xml文件,后面为请求路径
方式二:在命令行直接发送xml结构数据
[plain] view plain copy
-
root [ /apps ]$ curl -H 'content-type: application/xml' -X POST -d '<?xml version="1.0" encoding="UTF-8"?><userinfoReq><subsNumber>13814528620</subsNumber><type>3</type></userinfoReq>' http://172.19.219.xx:8081/csp/faq/actDiaUserInfo.action
或者
[plain] view plain copy
-
root [ /apps ]$ echo '<?xml version="1.0" encoding="UTF-8"?><userinfoReq><subsNumber>13814528620</subsNumber><type>3</type></userinfoReq>'|curl -X POST -H'Content-type:text/xm' -d @- http://172.19.xx.xx:8081/csp/faq/actDiaUserInfo.action
ps:其中<?xml version...>就是要post的xml 文件,后面是请求路径,linux上双引号或单引号之间嵌套需要使用反斜杠 \ 进行转义
响应消息:
[plain] view plain copy
-
<?xml version="1.0" encoding="utf-8"?><result><result_code>0</result_code><result_text>success</result_text><getUserinfoRsp><userInfo><identityID>1117384802</identityID><phone>13814528620</phone><email>13814528620@139.com</email><accountID></accountID><province>江苏</province><city>南京</city><passId>7775637869243</passId></userInfo></getUserinfoRsp></result>
4、json格式post请求
接口如下:
请求消息:
方式一:发送磁盘上面的JSON文件(推荐)
[plain] view plain copy
-
root [ /apps ]$ curl -X POST -H 'content-type: application/json' -d @/apps/myjsonfile.txt http://192.168.129.xx/AntiRushServer/api/ActivityAntiRush
ps:其中myjsonfile.txt为磁盘上面的JSON文件,后面为请求路径
方式二:在命令行直接发送JSON结构数据
[plain] view plain copy
-
root [ ~ ]$ curl -H 'content-type: application/json' -X POST -d '{"accountType":"4","channel":"1","channelId":"YW_MMY","uid":"13154897541","phoneNumber":"13154897541","loginSource":"3","loginType":"1","userIp":"192.168.2.3","postTime":"14633fffffffffff81286","userAgent":"Windows NT","imei":"352600051025733","macAddress":"40:92:d4:cb:46:43","serialNumber":"123"}' http://192.168.129.xx/AntiRushServer/api/ActivityAntiRush
响应消息:
[plain] view plain copy
-
{"code":"4000","message":"参数错误:time的值不是UInt"}
五、webservice请求
接口如下:
方式一:发送磁盘上面的请求报文文件(推荐)
[plain] view plain copy
-
root [ /apps ]$ curl -H 'Content-Type: text/xml;charset=UTF-8;SOAPAction:""' -d @/apps/mysoapfile.xml http://172.18.173.xx:8085/csp-magent-client/madapterservices/madapter/lmCountAccessor
ps:其中myjsonfile.txt为磁盘上面的请求报文文件,后面为请求路径
方式二:在命令行直接发送xml结构数据
[plain] view plain copy
[plain] view plain copy
-
root [ /apps ]$ curl -H 'content-type: application/xml' -d '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.accessor.madapter.csp.huawei.com"><soapenv:Header /><soapenv:Body><ser:leaveMessageCount><ser:in0><![CDATA[20161011160516XdznbN]]></ser:in0><ser:in1><![CDATA[1600106496388382726]]></ser:in1><ser:in2><![CDATA[14]]></ser:in2><ser:in3><![CDATA[<extendParams><channelid>1600</channelid><servicetype></servicetype><appid></appid><usertype>10</usertype><userid>6496388382726</userid><msisdn>13814528620</msisdn><email></email><account></account><nickname></nickname><questionType></questionType></extendParams>]]></ser:in3></ser:leaveMessageCount></soapenv:Body></soapenv:Envelope>' http://172.18.173.xx:8085/csp-magent-client/madapterservices/madapter/lmCountAccessor
响应消息
[plain] view plain copy
-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:leaveMessageCountResponse xmlns:ns1="http://service.accessor.madapter.csp.huawei.com"><ns1:out>8</ns1:out></ns1:leaveMessageCountResponse></soap:Body></soap:Envelope>
-
交通事故调解协议书:https://www.nanss.com/gongzuo/12394.html 投资申请报告:https://www.nanss.com/gongzuo/13079.html 数学童话故事:https://www.nanss.com/yuedu/13620.html 幼儿园班务总结:https://www.nanss.com/gongzuo/13470.html 教师教学工作计划:https://www.nanss.com/gongzuo/12453.html 世界末日作文:https://www.nanss.com/xuexi/11985.html 寻求合作意向书:https://www.nanss.com/gongzuo/13159.html 预警等级:https://www.nanss.com/shenghuo/12130.html 南瓜的功效与作用:https://www.nanss.com/shenghuo/12316.html 桀骜不驯的网名:https://www.nanss.com/mingcheng/12328.html 满天星花语和寓意:https://www.nanss.com/shenghuo/12122.html 书香伴我成长作文:https://www.nanss.com/xuexi/13428.html 明信片祝福语:https://www.nanss.com/xuexi/11735.html 马云经典语录:https://www.nanss.com/yulu/11869.html 工作责任心:https://www.nanss.com/gongzuo/13913.html 瘦肉汤怎么做补血补气:https://www.nanss.com/yinshi/11550.html 刚去世的外婆伤感句子:https://www.nanss.com/yulu/11979.html 申诉书范文:https://www.nanss.com/gongzuo/13731.html 幼儿园晨检制度:https://www.nanss.com/gongzuo/13281.html 描写端午节的优秀作文700字:https://www.nanss.com/xuexi/13458.html 流连忘返造句:https://www.nanss.com/xuexi/11865.html 童年读后感600字:https://www.nanss.com/xuexi/11645.html 小学教学反思:https://www.nanss.com/xuexi/13357.html 学年是一学期还是一年:https://www.nanss.com/wenti/11931.html 优秀入党志愿书3000字:https://www.nanss.com/xuexi/13152.html 我的新语文老师作文:https://www.nanss.com/xuexi/11981.html 独一无二的情侣名俩字:https://www.nanss.com/mingcheng/11714.html 文员职位描述:https://www.nanss.com/gongzuo/13033.html 教师入党志愿书:https://www.nanss.com/gongzuo/12768.html 汇报材料范文:https://www.nanss.com/gongzuo/13122.html(0) 回复 (0)
-
讨债公司/蓝月传奇辅助/蓝月辅助(0) 回复 (0)
-
您的想法(0) 回复 (0)