zoukankan      html  css  js  c++  java
  • get&&post请求

    get&&post请求

    request.js文件

    import { fetch as fetchPro } from "whatwg-fetch";
    import qs from "qs";
    
    
    const get = (options) => {
        let url = options.url;
        let data = options.data;
    
        if (data) {
            var str = "";
            for (var key in data) {
                str += "&" + key + "=" + data[key];
            }
    
            url = url + "?" + str.slice(1);
        }
    
    
    
        var result = fetchPro(url, {
            headers: {
                "content-type": "application/json",
                ...options.headers
            }
        }).then(res => res.json());
    
    
        return result;
    }
    
    
    const post = (options) => {
        var result = fetchPro(options.url, {
            method: options.method,
            body: qs.stringify(options.data),
            headers: {
                "content-type": "application/x-www-form-urlencoded"
            }
        }).then(res => res.json())
    
        return result;
    }
    
    
    export default {
        get,
        post
    }
  • 相关阅读:
    request:getParameter和getAttribute区别
    JSP登录页面大小
    单例模式详情
    关于HTML的总结
    遍历HashMap的四种方法
    三层开发原则
    java日期
    oracle6
    tomcat
    Linux命令
  • 原文地址:https://www.cnblogs.com/Bree/p/12003760.html
Copyright © 2011-2022 走看看