-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgolang-allocate-number.go
39 lines (29 loc) · 1.03 KB
/
golang-allocate-number.go
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
37
38
39
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 allocate a new number!")
data := url.Values{
"country": {"se"},
//"sms_url": {"http://www.example.com/sms"}, //Optional
//"mms_url": {"http://www.example.com/mms"}, //Optional
//"voice_start": {"http://www.example.com/calls"}, //Optional
//"capabilities": {"sms", "voice", "mms" }, //Optional
}
req, err := http.NewRequest("POST", "https://api.46elks.com/a1/Numbers", 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))
}