first commit

master
esterfreyja 1 year ago
commit bea6c22195

@ -0,0 +1,28 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"log"
)
type Data struct {
identifier string
password string
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
var data Data
err := json.NewDecoder(r.Body).Decode(&data)
if err != nil {
http.Error(w,err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "Data: %+v", data)
}
func main() {
http.HandleFunc("/", handleRequest)
log.Fatal(http.ListenAndServe(":8088", nil))
}

@ -0,0 +1,41 @@
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
)
type Data struct {
identifier string
password string
}
func main() {
url := "http://localhost:8088" // Remplacez par l'URL de votre choix
data := Data {
identifier: "machevaldo",
password: "superPassword"}
jsonData, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
Loading…
Cancel
Save