Skip to content

Instantly share code, notes, and snippets.

@slav123
Created June 30, 2022 06:34
Show Gist options
  • Save slav123/8dc9aabf084a1f03a30b24c14ace2e83 to your computer and use it in GitHub Desktop.
Save slav123/8dc9aabf084a1f03a30b24c14ace2e83 to your computer and use it in GitHub Desktop.
golang post query with host header oberri
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func main() {
url := "https://"
method := "POST"
payload := strings.NewReader(`{
"jsonrpc": "2.0",
"id": 0,
"method": "listRecords"
}`)
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: transport}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
// this is correct
req.Host = ""
// this won't work
req.Header.Add("Host", "")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
fmt.Printf("%v", res.Request.Response)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment