|
@@ -1,17 +1,21 @@
|
|
1
|
+// import axios from 'axios';
|
|
2
|
+import $ from "jquery"
|
|
3
|
+
|
1
|
4
|
export class HTTP {
|
2
|
5
|
|
3
|
6
|
constructor(url){
|
4
|
|
- this.base_url = 'http://204.48.25.93:8081';
|
|
7
|
+ this.base_url = 'http://204.48.25.93:8081/users';
|
5
|
8
|
this.url = this.base_url + url
|
|
9
|
+ this.api = 'http://204.48.25.93:8081/user?user=patrik&password=12345'
|
6
|
10
|
}
|
7
|
11
|
|
8
|
|
- async post(body){
|
|
12
|
+ async post(){
|
9
|
13
|
try{
|
10
|
14
|
|
11
|
|
- let request = fetch(this.url , {
|
|
15
|
+ let request = fetch(this.api, {
|
12
|
16
|
method: 'POST',
|
13
|
17
|
mode: 'cors',
|
14
|
|
- cache: 'no-cache',
|
|
18
|
+ // cache: 'no-cache',
|
15
|
19
|
headers: {
|
16
|
20
|
"Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
|
17
|
21
|
"Connection": "keep-alive",
|
|
@@ -38,23 +42,36 @@ export class HTTP {
|
38
|
42
|
}
|
39
|
43
|
}
|
40
|
44
|
|
41
|
|
- async get() {
|
|
45
|
+ async get_() {
|
42
|
46
|
|
43
|
47
|
// POST request using fetch with async/await
|
44
|
48
|
const requestOptions = {
|
45
|
49
|
method: 'POST',
|
46
|
|
- headers : new Headers({
|
|
50
|
+ headers : new Headers( {
|
47
|
51
|
'Content-Type': 'application/json',
|
48
|
52
|
'Access-Control-Allow-Origin': '*',
|
49
|
|
- }),
|
|
53
|
+ 'Access-Control-Request-Method' : 'POST',
|
|
54
|
+ } ),
|
50
|
55
|
// body: JSON.stringify({ title: 'React POST Request Example' })
|
51
|
|
- };
|
52
|
|
- const response = await fetch(this.url, requestOptions);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ let response = await fetch(this.api, requestOptions);
|
53
|
59
|
// const data =
|
54
|
60
|
console.log(response)
|
55
|
61
|
// this.setState({ postId: data.id });
|
56
|
62
|
}
|
57
|
63
|
|
58
|
64
|
|
|
65
|
+ async get(){
|
|
66
|
+ $.ajax(this.url, {
|
|
67
|
+ contentType : 'application/json',
|
|
68
|
+ type : 'POST',
|
|
69
|
+ onSucces : (res) => console.log(res),
|
|
70
|
+ onError : (err) => console.log(err),
|
|
71
|
+ })
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
59
|
76
|
}
|
60
|
77
|
|