httpSend

发送http请求

目前為 2018-12-29 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/376085/657823/httpSend.js

  1. /*
  2. *使用httpSend()函数调用,需把@require放在// @grant GM_xmlhttpRequest之后
  3. *参数详解:
  4. *url:请求的url,必须!
  5. *type:请求方式(get/post),必须!
  6. *mode:请求调用函数(jq/gm),必须!
  7. *headers:自定义请求头,仅gm模式可用
  8. *data:要发送的数据,仅post方式可用
  9. *timeout:请求超时时间,单位毫秒
  10. *dataType:返回数据类型(arraybuffer,blob,json)
  11. *callback:请求完成回调函数
  12. *username:用户名
  13. *password:密码
  14. */
  15. function httpSend(i,e={}){
  16. if(!i.url){throw "缺少请求的url!"};
  17. if(!i.type){throw "缺少请求方式(get/post)!"};
  18. if(!i.mode){throw "缺少请求模式(jq/gm)!"};
  19. e.url=i.url;
  20. i.username&&(e.username=i.username);
  21. i.password&&(e.password=i.password);
  22. i.data&&(e.data=i.data);
  23. i.timeout?e.timeout=i.timeout:e.timeout=30000;
  24. if(/^jq$/i.test(i.mode)){
  25. e.xhrFields={withCredentials: true};
  26. e.crossDomain=true;
  27. e.cache=false;
  28. e.type=i.type;
  29. i.dataType&&(e.dataType=i.dataType);
  30. i.callback&&(e.complete=i.callback);
  31. $.ajax(e);
  32. }else if(/^gm$/i.test(i.mode)){
  33. i.type&&(e.method=i.type.toUpperCase());
  34. i.headers&&(e.headers=i.headers);
  35. i.dataType&&(e.responseType=i.dataType);
  36. i.callback&&(e.onload=i.callback);
  37. GM_xmlhttpRequest(e);
  38. }else{throw "此请求模式("+i.mode+")不存在!"}
  39. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址