go(土)语(拨)言(鼠) http.get报错x509: certificate signed by unknown authority

开篇致谢:https://studygolang.com/articles/11175

我只是想获取一个js文件内容:https://www.hongniang.com/public/js/city.min.js

用http.get请求时发生报错

panic: Get https://www.hongniang.com/public/js/city.min.js: x509: certificate signed by unknown authority

于是用postman尝试下,把head都写上
psotman告诉我:

Could not get any response
There was an error connecting to https://www.hongniang.com/public/js/city.min.js.

???为什么我浏览器可以但是这个不行
只好百度一下,emmmm 看到了开头致谢的文章,好的 问题解决(早这么做不就行了嘛)
问题x509的原因竟然是?:
模拟浏览器(client)端默认要对服务端传过来的数字证书进行校验
(我怎么知道你的数字证书是啥啊!摔)
于是告诉我,我们可以忽略这个证书:

	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	
	client := &http.Client{Transport: tr}   //学艺不精 别问我为啥这么设置 我不懂啊

结果当然大圆满咯

{“citylist”:[{“p”:“北京”,“c”:[{“n”:“东城区”},{“n”:“西城区”},{“n”:“崇文区”},{“n”:“宣武区”},{“n”:“朝阳区”},{“n”:“丰台区”},…

你可能感兴趣的:(学习日记)