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