Valentin Gomez

All generations.

generate functionTue, 03 Jan 2023

post an api rest and get its value

package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" ) type User struct { Id int `json:"id"` Name string `json:"name"` } func main() { url := "https://jsonplaceholder.typicode.com/users/1" resp, _ := http.Get(url) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) var user User json.Unmarshal(body, &user) fmt.Println(user) }

generate functionTue, 03 Jan 2023

post an api rest using cuit value and get an answer

func main() { fmt.Println("start") cuit := "20-25851149-4" apiURL := "https://api.afip.gob.ar/sr-padron/v2/persona/" + cuit req, err := http.NewRequest("GET", apiURL, nil) if err != nil { panic(err.Error()) } client := &http.Client{ Timeout: time.Second * 10, } req.SetBasicAuth("fakeuser", "fakepassword") req.Header.Add("padron-usuario", "fakeuser") req.Header.Add("padron-password", "fakepassword") req.Header.Add("padron-token", "fakeuser") resp, err := client.Do(req) fmt.Println(resp) body, err := ioutil.ReadAll(resp.Body) if err != nil {

generate functionTue, 03 Jan 2023

interact with https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

[HttpPost] [Route("Login")] public IHttpActionResult Login(Login login) { try { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SINTIA"].ConnectionString)) { var query = "select * from [dbo].[User] where [UserName] = @username and [Password] = @password"; var cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("username", login.UserName); cmd.Parameters.AddWithValue("password", login.Password); conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); var accesstoken = Guid.NewGuid(); var query2 = "update [dbo].[User] set [AccessToken] = @accesstoken, [LastLogin] = getdate() where [UserName] = @username and [Password] = @password"; var cmd2 =

generate functionTue, 03 Jan 2023

interact with Ratificacion/Login in https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

func login(url string, username string, password string) map[string]interface{} { values := map[string]string{"Usuario": username, "Clave": password} jsonValue, _ := json.Marshal(values) response, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue)) if err != nil { panic(err) } defer response.Body.Close() bodyBytes, err := ioutil.ReadAll(response.Body) if err != nil { panic(err) } bodyString := string(bodyBytes) fmt.Println(bodyString) var result map[string]interface{} json.Unmarshal(bodyBytes, &result) return result }

generate functionTue, 03 Jan 2023

interact with https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

func login(username, password string) (Token, error) { res, err := http.Post("https://apiadv.sintia.com.ar/api/Login", "application/json", strings.NewReader(fmt.Sprintf(`{"username": "%s", "password": "%s"}`, username, password)), ) if err != nil { return "", err } defer res.Body.Close() if res.StatusCode != 200 { return "", errors.New("invalid username/password") } var t Token dec := json.NewDecoder(res.Body) if err := dec.Decode(&t); err != nil { return "", err } return t, nil }

generate functionTue, 03 Jan 2023

connect to an api rest via jwt and return an specific value and show it

func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://test.test.com", nil) req.Header.Set("Authorization", "Bearer " + "asdasdasdasd") req.Header.Set("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) }

generate functionTue, 03 Jan 2023

POST Ratificacion/Login in https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

func RatificacionLogin() { url := "https://apiadv.sintia.com.ar/Ratificacion/Login" payload := strings.NewReader("{\n\t\"Username\":\"XXXXXX\",\n\t\"Password\":\"XXXXXXX\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("content-type", "application/json") req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) }

generate functionThu, 05 Jan 2023

Clasificar contenido de imagenes y guardar los archivos en carpetas distintas

class ClassifyImages { private string _imagesPath; private string _imagesClassPath; private string _imagesClassPath; private string _imagesClassPath; private string _imagesClassPath; private string _imagesClassPath; private string _imagesClassPath; public ClassifyImages(string imagesPath) { _imagePath = imagesPath; } public void ClassifyContent() { string[] fileEntries = Directory.GetFiles(_imagesPath); foreach (string fileName in fileEntries) { string[] parts = fileName.Split('\\'); string[] nameParts = parts[1].Split('.'); string tag = nameParts[0]; string filePath = $"{_imagesPath}{parts[1]}"; switch (tag) { case "M": processFile("M", filePath); break; case "A": processFile("A", filePath); break; case "N":

generate functionTue, 03 Jan 2023

POST data from https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

func Login(username, password string) { url := "https://apiadv.sintia.com.ar/Ratificacion/Login" var jsonStr = []byte(`{"Username":"` + username + `","Password":"` + password + `"}`) req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() fmt.Println("response Status:", resp.Status) fmt.Println("response Headers:", resp.Header) body, _ := ioutil.ReadAll(resp.Body) fmt.Println("response Body:", string(body)) }

generate functionTue, 03 Jan 2023

POST Ratificacion/Login in https://apiadv.sintia.com.ar/Help/Api/POST-Ratificacion-Login

public class LoginPost { public string User { get; set; } public string Password { get; set; } } [HttpPost] public async Task<IActionResult> Login() { var body = await Request.Body.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject<LoginPost>(body); var token = new TokenJWT(); if (data.User == "admin" && data.Password == "admin") { string jwt = token.GenerateToken(data.User); return Ok(jwt); } return Unauthorized(); }

Questions about programming?Chat with your personal AI assistant