Explorar el Código

test http service

amenpunk hace 4 años
padre
commit
f839f75cce
Se han modificado 2 ficheros con 32 adiciones y 14 borrados
  1. 6 5
      src/Pages/Login.jsx
  2. 26 9
      src/Utils/HTTP.js

+ 6 - 5
src/Pages/Login.jsx

@@ -18,7 +18,7 @@ import useAuth from '../Auth/useAuth';
 import { useFormik } from 'formik';
 import * as Yup from 'yup';
 
-// import { HTTP } from '../Utils/HTTP.js'
+import { HTTP } from '../Utils/HTTP.js'
 
 const LoginSchema = Yup.object().shape({
     email : Yup
@@ -35,7 +35,6 @@ const LoginSchema = Yup.object().shape({
 const theme = createTheme();
 
 export function Login() {
-
     let auth = useAuth();
     let navigate = useNavigate()
 
@@ -46,13 +45,15 @@ export function Login() {
         },
         validationSchema: LoginSchema,
         onSubmit: (values) => {
-            // let { email, password } = values
+            let { email, password } = values
+            console.log(email,password);
             // let request = new HTTP('/user?' + `user=${email}&password=${password}`)
-            // request.get()
+            let request = new HTTP()
+            request.post()
             // toast.success('Bienvenido!!')
             // toast.error("This didn't work.")
             // return navigate('/dashboard/home')
-            auth.login(values)
+            // auth.login(values)
         },
     });
 

+ 26 - 9
src/Utils/HTTP.js

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