|
@@ -1,17 +1,21 @@
|
|
|
|
|
+// import axios from 'axios';
|
|
|
|
|
+import $ from "jquery"
|
|
|
|
|
+
|
|
|
export class HTTP {
|
|
export class HTTP {
|
|
|
|
|
|
|
|
constructor(url){
|
|
constructor(url){
|
|
|
- this.base_url = 'http://204.48.25.93:8081';
|
|
|
|
|
|
|
+ this.base_url = 'http://204.48.25.93:8081/users';
|
|
|
this.url = this.base_url + url
|
|
this.url = this.base_url + url
|
|
|
|
|
+ this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async post(body){
|
|
|
|
|
|
|
+ async post(){
|
|
|
try{
|
|
try{
|
|
|
|
|
|
|
|
- let request = fetch(this.url , {
|
|
|
|
|
|
|
+ let request = fetch(this.api, {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
mode: 'cors',
|
|
mode: 'cors',
|
|
|
- cache: 'no-cache',
|
|
|
|
|
|
|
+ // cache: 'no-cache',
|
|
|
headers: {
|
|
headers: {
|
|
|
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
|
|
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
|
|
|
"Connection": "keep-alive",
|
|
"Connection": "keep-alive",
|
|
@@ -38,23 +42,36 @@ export class HTTP {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async get() {
|
|
|
|
|
|
|
+ async get_() {
|
|
|
|
|
|
|
|
// POST request using fetch with async/await
|
|
// POST request using fetch with async/await
|
|
|
const requestOptions = {
|
|
const requestOptions = {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
- headers : new Headers({
|
|
|
|
|
|
|
+ headers : new Headers( {
|
|
|
'Content-Type': 'application/json',
|
|
'Content-Type': 'application/json',
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
- }),
|
|
|
|
|
|
|
+ 'Access-Control-Request-Method' : 'POST',
|
|
|
|
|
+ } ),
|
|
|
// body: JSON.stringify({ title: 'React POST Request Example' })
|
|
// body: JSON.stringify({ title: 'React POST Request Example' })
|
|
|
- };
|
|
|
|
|
- const response = await fetch(this.url, requestOptions);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let response = await fetch(this.api, requestOptions);
|
|
|
// const data =
|
|
// const data =
|
|
|
console.log(response)
|
|
console.log(response)
|
|
|
// this.setState({ postId: data.id });
|
|
// 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),
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|