-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathgolang-send-sms.go
More file actions
36 lines (26 loc) · 843 Bytes
/
golang-send-sms.go
File metadata and controls
36 lines (26 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import "net/url"
import "io/ioutil"
import "fmt"
import "net/http"
import "bytes"
import "strconv"
func main() {
fmt.Println("I will now try to send a Message!")
data := url.Values{
"from": {"GoElk"},
"to": {"+46700000000"},
"message":{"Hej på dig!"}}
req, err := http.NewRequest("POST", "https://api.46elks.com/a1/SMS", bytes.NewBufferString(data.Encode()))
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
req.SetBasicAuth("<API Username>", "<API Password>")
client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Oh dear!!!")
}
fmt.Println(string(body))
}