Created
October 8, 2016 03:01
-
-
Save sdimitro/e0c46582b7f2f628c037549c1df0c428 to your computer and use it in GitHub Desktop.
Szymon test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
func main() { | |
url := "http://localhost:8082/api/sensor_data" | |
var jsonStr = []byte(`{ | |
"serial_number": 1, | |
"name": "RPI 3", | |
"location": "IIT Tower Vault 1 SW Corner", | |
"temperature": 20.1, | |
"pressure": 760.2, | |
"humidity": 80.2, | |
"water_level": 2 | |
}`) | |
r, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) | |
r.Header.Set("X-Custom-Header", "MikeInDaHouse") | |
r.Header.Set("Content-Type", "application/json") | |
client := &http.Client{} | |
resp, err := client.Do(r) | |
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment