Created
January 20, 2016 19:39
-
-
Save u-mulder/2d16a24f5bd028093359 to your computer and use it in GitHub Desktop.
Go POST request to cssminifier.com
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" | |
"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