autojs post请求与get请求
比如服务器上存有一段json数据。
{ "ret": 200, "data": { "name": "飞云脚本圈", "url": "http://www.feiyunjs.com" }, "msg": "" }
我们要获取其中的name值。
//此代码由飞云脚本圈原创(www.feiyunjs.com) //接口采用PhalApi开发 let url = "http://news.feiyunjs.com/phalapi/public/"; let res = http.post(url, { "service": "App.Zllgcimei.Imei", "imei": device.getIMEI(), "imei_tag": "测试标签", "whos": "feiyun", }); let appName; let html = res.body.string(); //取页面html源码 // log(html) let json = JSON.parse(html); if (json.ret == "200") { appName = json.data.name } else { log("请求失败!") } log(appName)
————————————————
版权声明:本文为CSDN博主「博客8712」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_33962835/article/details/104272201
get
/** url123 = 网址 lgg = 1 则打印网址日志 mods 0=返回源码 1=返回json 2=返回字节 3=返回body **/ function fa_get(url123,lgg,mods){ if(lgg == 1){ console.log("[fa_get]",url123); } var fan = undefined; var codeee = undefined; try{ codeee = http.get(url123); }catch(e){ codeee = undefined; console.log("[fa_get]","get异常1:"+e); } if(codeee == undefined){ try{ codeee = http.get(url123); }catch(e){ codeee = undefined; console.log("[fa_get]","get异常2:"+e); } if(codeee == undefined){ try{ sleep(5000); codeee = http.get(url123); }catch(e){ codeee = undefined; console.log("[fa_get]","get异常3:"+e); } } } if(codeee != undefined && codeee.statusCode == 200){ if(mods == 0){ try{ fan = codeee.body.string(); }catch(e){ fan = undefined; console.log("[fa_get]","codeee.body.string():"+e) } }else if(mods == 1){ try{ fan = codeee.body.json(); }catch(e){ fan = undefined; console.log("[fa_get]","codeee.body.json():"+e) } }else if(mods == 2){ try{ fan = codeee.body.bytes(); }catch(e){ fan = undefined; console.log("[fa_get]","codeee.body.bytes():"+e) } }else if(mods == 3){ try{ fan = codeee.body; }catch(e){ fan = undefined; console.log("[fa_get]","codeee.body:"+e) } } } return fan; }