|
1 | | -import axios from 'axios'; |
2 | | -import ApiConstants from './ApiConstants'; |
3 | | - |
4 | | -class AxiosNetworkTester { |
5 | | - sendGetRequest() { |
6 | | - axios |
7 | | - .get(ApiConstants.GET_URL) |
8 | | - .then(function (response) { |
9 | | - alert('Request sent.'); |
10 | | - }) |
11 | | - .catch(function (error) { |
12 | | - alert('Request error.'); |
13 | | - }); |
14 | | - } |
15 | | - |
16 | | - sendPostRequest() { |
17 | | - axios |
18 | | - .post(ApiConstants.POST_URL, { |
19 | | - firstParam: 'firstParam', |
20 | | - secondParam: 'secondParam', |
21 | | - }) |
22 | | - .then(function (response) { |
23 | | - alert('Request sent.'); |
24 | | - }) |
25 | | - .catch(function (error) { |
26 | | - alert('Request error.'); |
27 | | - }); |
28 | | - } |
29 | | - |
30 | | - sendErrorRequest() { |
31 | | - axios |
32 | | - .get(ApiConstants.ERROR_URL) |
33 | | - .then(function (response) { |
34 | | - alert('Request sent.'); |
35 | | - }) |
36 | | - .catch(function (error) { |
37 | | - alert('Request error.'); |
38 | | - }); |
39 | | - } |
40 | | - |
41 | | - sendTimeoutRequest() { |
42 | | - axios |
43 | | - .post( |
44 | | - ApiConstants.TIMEOUT_URL, |
45 | | - { |
46 | | - firstParam: 'firstParam', |
47 | | - secondParam: 'secondParam', |
48 | | - }, |
49 | | - { |
50 | | - timeout: 1, |
51 | | - }, |
52 | | - ) |
53 | | - .then(function (response) { |
54 | | - alert('Request sent.'); |
55 | | - }) |
56 | | - .catch(function (error) { |
57 | | - alert('Request error.'); |
58 | | - }); |
59 | | - } |
60 | | - |
61 | | - postFileRequest() { |
62 | | - const formData = new FormData(); |
63 | | - //formData.append('file', {uri: path, name: 'file.txt', type: 'text/plain'}); |
64 | | - formData.append('userId', 'xzy'); |
65 | | - |
66 | | - const config = { |
67 | | - headers: { |
68 | | - accept: 'application/json', |
69 | | - }, |
70 | | - }; |
71 | | - |
72 | | - axios |
73 | | - .post(ApiConstants.FILE_URL, formData, config) |
74 | | - .then(function (response) { |
75 | | - alert('Request sent.'); |
76 | | - }) |
77 | | - .catch(function (error) { |
78 | | - alert('Request error.'); |
79 | | - }); |
80 | | - } |
81 | | - |
82 | | - getImageRequest() { |
83 | | - axios |
84 | | - .get(ApiConstants.IMAGE_URL, { |
85 | | - responseType: 'blob', |
86 | | - }) |
87 | | - .then(function (response) { |
88 | | - alert('Request sent.'); |
89 | | - }) |
90 | | - .catch(function (error) { |
91 | | - alert('Request error.'); |
92 | | - }); |
93 | | - } |
94 | | -} |
95 | | - |
96 | | -export default AxiosNetworkTester; |
| 1 | +import axios from 'axios'; |
| 2 | +import ApiConstants from './ApiConstants'; |
| 3 | + |
| 4 | +class AxiosNetworkTester { |
| 5 | + sendGetRequest() { |
| 6 | + axios |
| 7 | + .get(ApiConstants.GET_URL, { |
| 8 | + headers: { |
| 9 | + 'number-header': 100, |
| 10 | + 'array-header': ['hello', 'world'], |
| 11 | + }, |
| 12 | + }) |
| 13 | + .then(function (response) { |
| 14 | + alert('Request sent.'); |
| 15 | + }) |
| 16 | + .catch(function (error) { |
| 17 | + alert('Request error.'); |
| 18 | + }); |
| 19 | + } |
| 20 | + |
| 21 | + sendPostRequest() { |
| 22 | + axios |
| 23 | + .post(ApiConstants.POST_URL, { |
| 24 | + firstParam: 'firstParam', |
| 25 | + secondParam: 'secondParam', |
| 26 | + }) |
| 27 | + .then(function (response) { |
| 28 | + alert('Request sent.'); |
| 29 | + }) |
| 30 | + .catch(function (error) { |
| 31 | + alert('Request error.'); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + sendErrorRequest() { |
| 36 | + axios |
| 37 | + .get(ApiConstants.ERROR_URL) |
| 38 | + .then(function (response) { |
| 39 | + alert('Request sent.'); |
| 40 | + }) |
| 41 | + .catch(function (error) { |
| 42 | + alert('Request error.'); |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + sendTimeoutRequest() { |
| 47 | + axios |
| 48 | + .post( |
| 49 | + ApiConstants.TIMEOUT_URL, |
| 50 | + { |
| 51 | + firstParam: 'firstParam', |
| 52 | + secondParam: 'secondParam', |
| 53 | + }, |
| 54 | + { |
| 55 | + timeout: 1, |
| 56 | + }, |
| 57 | + ) |
| 58 | + .then(function (response) { |
| 59 | + alert('Request sent.'); |
| 60 | + }) |
| 61 | + .catch(function (error) { |
| 62 | + alert('Request error.'); |
| 63 | + }); |
| 64 | + } |
| 65 | + |
| 66 | + postFileRequest() { |
| 67 | + const formData = new FormData(); |
| 68 | + //formData.append('file', {uri: path, name: 'file.txt', type: 'text/plain'}); |
| 69 | + formData.append('userId', 'xzy'); |
| 70 | + |
| 71 | + const config = { |
| 72 | + headers: { |
| 73 | + accept: 'application/json', |
| 74 | + }, |
| 75 | + }; |
| 76 | + |
| 77 | + axios |
| 78 | + .post(ApiConstants.FILE_URL, formData, config) |
| 79 | + .then(function (response) { |
| 80 | + alert('Request sent.'); |
| 81 | + }) |
| 82 | + .catch(function (error) { |
| 83 | + alert('Request error.'); |
| 84 | + }); |
| 85 | + } |
| 86 | + |
| 87 | + getImageRequest() { |
| 88 | + axios |
| 89 | + .get(ApiConstants.IMAGE_URL, { |
| 90 | + responseType: 'blob', |
| 91 | + }) |
| 92 | + .then(function (response) { |
| 93 | + alert('Request sent.'); |
| 94 | + }) |
| 95 | + .catch(function (error) { |
| 96 | + alert('Request error.'); |
| 97 | + }); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +export default AxiosNetworkTester; |
0 commit comments