react native 网络请求

2018-06-21  本文已影响0人  牵着蜗牛散步Zz

1、fetch PUT、POST、GET请求方法:

requestToTest() {
        return fetch(BASE_NEWUC_URL + 'checkSign/JCBSP000080-01', {
            method: 'GET',
        }) 
        .then((response) => response.json())
        .then((data) => {
            console.log(data);
            return data;
        }).catch((err) => {
            console.log(err);
        });
    }
requestToLogin(account, password) {

        return fetch(BASE_NEWUC_URL + 'login', {
            method: 'PUT',
            headers: {
                'Accept': 'application/json',
                "Content-Type": "application/x-www-form-urlencoded"
            },
            body: `account=${account}&password=${password}&source=AJ`
        })
        .then((response) => response.json())
        .then((data) => {
            console.log(data);
            return data;
        }).catch((err) => {
            console.log(err);
        });
}
requestToGetApplyId() {
        return fetch('http://splab.haocheedai.com:8800/fmbg/fm-bg/getApplyId', {
            method: 'POST',
            headers: {
                'Authorization': 'bc499bf86f800af78fcf28f075eb76ff',
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                'name': '魏昌洲',
                'telephone': '17621711933',
                'certNo': '420583199306053410'
            })
        }) 
        .then((response) => response.json())
        .then((data) => {
            console.log(data);
            return data;
        }).catch((err) => {
            console.log(err);
        });
    }
上一篇 下一篇

猜你喜欢

热点阅读