1、案例描述
案例:我們的APP使用了某天氣預報接口,其接口描述如下:
接口名稱:根據(jù)城市名查詢天氣
接口地址:http://v.juhe.cn/weather/index
返回格式:json/xml
請求方式:get
請求示例:http://v.juhe.cn/weather/index?cityname=%E8%8B%8F%E5%B7%9E&key=您申請的KEY
請求參數(shù)說明:
名稱必填類型說明
citynameYstring城市名,如:"蘇州",需要utf8 urlencode
dtypeNstring返回數(shù)據(jù)格式:json或xml,默認json
formatNint未來7天預報(future)兩種返回格式,1或2,默認1
keyYstring您申請到的訪問密鑰
返回數(shù)據(jù)示例:
{
"resultcode": "200",
"reason": "查詢成功!",
"result": {
"sk": { /*當前實況天氣*/
"temp": "21", /*當前溫度*/
"wind_direction": "西風", /*當前風向*/
"wind_strength": "2級", /*當前風力*/
"humidity": "4%", /*當前濕度*/
"time": "14:25" /*更新時間*/
},
"today": {
"city": "天津",
"date_y": "2014年03月21日",
"week": "星期五",
"temperature": "8℃~20℃", /*今日溫度*/
"weather": "晴轉霾", /*今日天氣*/
"weather_id": { /*天氣唯一標識*/
"fa": "00", /*天氣標識00:晴*/
"fb": "53" /*天氣標識53:霾 如果fa不等于fb,說明是組合天氣*/
},
"wind": "西南風微風",
"dressing_index": "較冷", /*穿衣指數(shù)*/
"dressing_advice": "建議著大衣、呢外套加毛衣、衛(wèi)衣等服裝。", /*穿衣建議*/
"uv_index": "中等", /*紫外線強度*/
"comfort_index": "",/*舒適度指數(shù)*/
"wash_index": "較適宜", /*洗車指數(shù)*/
"travel_index": "適宜", /*旅游指數(shù)*/
"exercise_index": "較適宜", /*晨練指數(shù)*/
"drying_index": ""/*干燥指數(shù)*/
},
"future": [ /*未來幾天天氣*/
{
"temperature": "28℃~36℃",
"weather": "晴轉多云",
"weather_id": {
"fa": "00",
"fb": "01"
},
"wind": "南風3-4級",
"week": "星期一",
"date": "20140804"
},
{
"temperature": "28℃~36℃",
"weather": "晴轉多云",
"weather_id": {
"fa": "00",
"fb": "01"
},
"wind": "東南風3-4級",
"week": "星期二",
"date": "20140805"
},
{
"temperature": "27℃~35℃",
"weather": "晴轉多云",
"weather_id": {
"fa": "00",
"fb": "01"
},
"wind": "東南風3-4級",
"week": "星期三",
"date": "20140806"
},
{
"temperature": "27℃~34℃",
"weather": "多云",
"weather_id": {
"fa": "01",
"fb": "01"
},
"wind": "東南風3-4級",
"week": "星期四",
"date": "20140807"
},
{
"temperature": "27℃~33℃",
"weather": "多云",
"weather_id": {
"fa": "01",
"fb": "01"
},
"wind": "東北風4-5級",
"week": "星期五",
"date": "20140808"
},
{
"temperature": "26℃~33℃",
"weather": "多云",
"weather_id": {
"fa": "01",
"fb": "01"
},
"wind": "北風4-5級",
"week": "星期六",
"date": "20140809"
},
{
"temperature": "26℃~33℃",
"weather": "多云",
"weather_id": {
"fa": "01",
"fb": "01"
},
"wind": "北風4-5級",
"week": "星期日",
"date": "20140810"
}
]
},
"error_code": 0
}
2、實現(xiàn)過程
上面的案例中,我們需要模擬接口服務器返回天氣信息來進行APP測試,具體實現(xiàn)步驟如下:
(1)按照提供的“返回數(shù)據(jù)示例”格式準備好測試數(shù)據(jù),并保存為weather_response.json文件。
(2)打開fiddler,開啟自動響應功能,添加并編輯匹配規(guī)則,指定響應文件,如下圖所示:
(3)在瀏覽器地址欄中輸入 http://v.juhe.cn/weather/index?cityname=北京&key=您申請的KEY 進行效果測試,效果如下圖所示:
>>本文地址:http://uj2y2uok.com/zhuanye/2020/48353.html
聲明:本站稿件版權均屬中公教育優(yōu)就業(yè)所有,未經(jīng)許可不得擅自轉載。
1 您的年齡
2 您的學歷
3 您更想做哪個方向的工作?