React Native
악시오스 axios 사용법 ( 작성중 )
Machine_웅
2020. 4. 8. 22:15
728x90
반응형
https://github.com/axios/axios
react-native-axios
Promise based HTTP client for the browser and node.js
www.npmjs.com
import
import axios from 'axios';
async send_server() {
const server_url = 'http://192.168.25.13/index.php'
let options = {
method: 'POST',
url: server_url,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
},
data: {
property_one: "값",
property_two: "값2"
}
};
let response = await axios(options);
console.log(response)
if( response.status === 200 ){
let data = await response.data;
console.log(data)
}
}
async test(){
let pram = {
type : Platform.OS === 'ios' ? 'ios' : 'android',
version:version
}
const server_url = 'http://lovegru.eoapps.co.kr/api/version_check.php'
let options = {
method: 'POST',
url: server_url,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=UTF-8'
},
data: JSON.stringify(pram)
};
let response = await axios(options);
console.log(response)
if (response.status === 200) {
let data = await response.data;
console.log(data)
}
}
/* async test_axios(url,request_params){
let result = '';
let options = {
method: 'POST',
url: url,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify(request_params),
}
console.log(url+"===>","common - api_call - request_params >{\n}",JSON.stringify(request_params))
let response = await axios(options);
if (response.status === 200) {
let data = await response.data;
console.log(data)
result = data.json()
} else {
let data = await response.data;
result = data.json()
}
console.log("****************Result*****************")
console.log(result)
console.log("*********************************************\n\n\n\n\n")
}
*/
728x90
반응형