duanjiao6731
2016-03-08 15:09Go和UTF-8编码-转换是自动的吗?
I am making http requests using Go.
request, err := http.NewRequest("GET", url, nil)
This request, if successful, returns a response.
response, err := client.Do(request)
After receiving a response, I want to save the content.
content, err := ioutil.ReadAll(response.Body)
ioutil.WriteFile(destination, content, 0644)
I looked at the Headers of the responses.
response.Header.Get("Content-Type")
I saw the majority are already UTF-8 encoded, which is good. But there are some that have different encodings. I know Go has built in unicode support. Does that mean that if I write, for example, the content of a big-5 encoded page, it will be automatically converted to utf-8? Or do I need to manually decode using the big-5 encoding and re-encode using utf-8?
Basically, I want to ensure that everything that gets written is utf-8 encoded. What is the best way to achieve this?
Thanks!
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 在Go中使用C库时,如何正确地将UTF-8编码的char数组转换为Go字符串?
- cgo
- utf-8
- 2个回答
- 如何在Go中改善文件编码转换
- character-encoding
- python
- encoding
- io
- 1个回答
- 如何在Go中将所有编码都转换为UTF 8?
- encoding
- mongodb
- utf-8
- 3个回答
- Golang JSON封送将表情符号转换为问号
- json
- mysql
- 1个回答
- golang json marshal将标签转换为utf符号
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
换一换