// import axios from 'axios'; import $ from "jquery" export class HTTP_ { constructor(url){ this.base_url = 'http://204.48.25.93:8081/users'; this.url = this.base_url + url // this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345' this.api = 'http://psicoadmin.ditca.org:8081/user?user=patrik&password=12345' } async post(){ try{ let request = fetch(this.api, { method: 'POST', mode: 'cors', // cache: 'no-cache', headers: { "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate", "Connection": "keep-alive", "Content-Type": "application/json", "Date": new Date().toUTCString(), "Expires": 0, "Keep-Alive": "timeout=60", "Pragma": "no-cache", "Transfer-Encoding": "chunked", "Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "DENY", "X-XSS-Protection": 1 }, // body: body }); // let response = await request.json(); console.log(await request) }catch(error) { console.log(error) return { status : 0, message : error.message } } } async get_() { // POST request using fetch with async/await const requestOptions = { method: 'POST', headers : new Headers( { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Request-Method' : 'POST', } ), // body: JSON.stringify({ title: 'React POST Request Example' }) } let response = await fetch(this.api, requestOptions); // const data = console.log(response) // this.setState({ postId: data.id }); } async get(){ $.ajax(this.url, { contentType : 'application/json', type : 'POST', onSucces : (res) => console.log(res), onError : (err) => console.log(err), }) } }