Skip to content

Instantly share code, notes, and snippets.

@u-mulder
Created January 20, 2016 19:39
Show Gist options
  • Save u-mulder/2d16a24f5bd028093359 to your computer and use it in GitHub Desktop.
Save u-mulder/2d16a24f5bd028093359 to your computer and use it in GitHub Desktop.
Go POST request to cssminifier.com
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
func main() {
targetUrl := "http://cssminifier.com/raw"
file, err := ioutil.ReadFile("./raw.css")
if err != nil {
panic(err)
}
data := url.Values{}
data.Set("input", string(file))
r, _ := http.NewRequest("POST", targetUrl, bytes.NewBufferString(data.Encode()))
client := &http.Client{}
r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
resp, _ := client.Do(r)
if resp.Status == "200 OK" {
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bytes))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment