測試API接口:
http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getDatabaseInfo
請求數據要求參照API規範。
要求:將響應數據中手機號和歸屬地數據賦給全局變量(其他變量也可以)。
響應數據:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
<getMobileCodeInfoResult>13644556677:黑龍江 綏化 黑龍江移動神州行卡</getMobileCodeInfoResult>
</getMobileCodeInfoResponse>
</soap:Body>
</soap:Envelope>
在Tests斷言添加如下代碼:
//獲取xml響應數據
var reg = pm.response.text();
pm.globals.set("xmldata", reg);
//正則提取手機號歸屬地結果
var phone = reg.match(/[\\<]getMobileCodeInfoResult>([\S\s]*?)[\\<][\\/]getMobileCodeInfoResult.*/)[1];
pm.globals.set("phone_address", phone);
//正則提取手機號
var phone = reg.match(/[\\<]getMobileCodeInfoResult>([\S\s]*?):.*/)[1];
pm.globals.set("phone_Num", phone);
執行接口,查看變量。