thank you for your response,

This is for ""Clients TLS" not "Server TLS", and the target url is not 
google.com it is another server which supports "Clients tls". and even when 
I change the (and if you change https://google.com to https://www.google.com 
then 
you get the search page) I get no result.

any body have idea why it returns 200 even without make a request?


On Friday, October 9, 2020 at 12:40:16 PM UTC-4 b.ca...@pobox.com wrote:

> I suspect you may have misunderstood what a "CA Certificate" is.  It's not 
> the Certificate Signing Request (CSR) that you created for your own public 
> key.  It's the public key of the certificate authority which signed the 
> server's certificate (i.e. google.com).
>
> However, since google.com is signed by one of the standard public CAs, 
> you don't need to specify a CA certificate at all, and it will use your 
> system's default set of root CAs.
>
> The following variation of your code works for me.  I removed the client 
> cert/key as well, since google doesn't require you to present a client cert.
>
> package main
>
> import (
>   "fmt"
>   //log "github.com/sirupsen/logrus"
>   "github.com/valyala/fasthttp"
>   "crypto/tls"
>   //"crypto/x509"
>   //"io/ioutil"
> )
>
> func req(method string, url string, data []byte) (int, []byte) {
>     // Setup HTTPS client
>     tlsConfig := &tls.Config{
>       Certificates: []tls.Certificate{},
>     }
>
>   req := fasthttp.AcquireRequest()
>   req.SetRequestURI(url)
>   req.Header.SetMethod(method)
>   req.SetBody(data)
>   resp := fasthttp.AcquireResponse()
>
>   client := &fasthttp.Client{
>     TLSConfig: tlsConfig,
>   }
>   client.Do(req, resp)
>   statusCode := resp.StatusCode()
>   body := resp.Body()
>   return statusCode, body
> }
>
> func main(){
>   a, b := req("GET", "https://google.com";, nil)
>
>   fmt.Printf(string(b))
>   fmt.Println(a)
>
> }
>
> The result:
>
> <HTML><HEAD><meta http-equiv="content-type" 
> content="text/html;charset=utf-8">
> <TITLE>301 Moved</TITLE></HEAD><BODY>
> <H1>301 Moved</H1>
> The document has moved
> <A HREF="https://www.google.com/";>here</A>.
> </BODY></HTML>
> 301
>
> (and if you change https://google.com to https://www.google.com then you 
> get the search page)
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6e242f25-d34a-4f4a-9277-41a764d3a58dn%40googlegroups.com.

Reply via email to