Sign in New API Help About

Posting to the dpaste.com API with Go

515 bytes of Go
Created 3 years, 11 months ago by dpaste.com — public
Viewed 3,595 times
https://dpaste.com/6VSSDLMXV
COPY TO CLIPBOARD SOFT WRAP RAW TEXT DUPLICATE DIFF
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
)

// Note: This example code ignores errors
func main() {
	data := url.Values{}
	data.Set("content", "Hello!")
	data.Set("syntax", "go")
	client := &http.Client{}
	r, _ := http.NewRequest("POST", "https://dpaste.com/api/",
		strings.NewReader(data.Encode()))
	r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	res, _ := client.Do(r)
	body, _ := ioutil.ReadAll(res.Body)
	fmt.Println(string(body))
}

Related items


Share: