Created
June 30, 2022 06:34
-
-
Save slav123/8dc9aabf084a1f03a30b24c14ace2e83 to your computer and use it in GitHub Desktop.
golang post query with host header oberri
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 ( | |
"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