-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoterequest.go
45 lines (38 loc) · 1.01 KB
/
remoterequest.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
40
41
42
43
44
45
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
func makeHttpreservePOST() *http.Request {
serviceURL := defaulthpserver
resource := httpreserveFunction
data := url.Values{}
data.Set("url", link)
data.Set("filename", linklabel)
u, _ := url.ParseRequestURI(serviceURL)
u.Path = resource
r, _ := http.NewRequest("POST", u.String(), bytes.NewBufferString(data.Encode()))
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
return r
}
func makeRemoteRequest() {
client := &http.Client{}
resp, err := client.Do(makeHttpreservePOST())
if err != nil {
fmt.Fprintln(os.Stderr, "error making client request")
}
defer resp.Body.Close()
responseData, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Fprintln(os.Stderr, "error reading body")
}
fmt.Fprintln(os.Stderr, "Using httpreserve web service to retrieve data.")
fmt.Println(strings.Trim(string(responseData), " \n"))
}