美文网首页Golang 入门资料+笔记
go http 请求解析body err: invalid ch

go http 请求解析body err: invalid ch

作者: 五岁小孩 | 来源:发表于2021-02-24 22:23 被阅读0次

go http 请求解析body err: invalid character 'ï' looking for beginning of value

  • 错误

    http 请求解析body出错:

    invalid character 'ï' looking for beginning of value
    
  • 原因

    The server is sending you a UTF-8 text 
    string with a Byte Order Mark (BOM). 
    The BOM identifies that the text is UTF-8 encoded,
    but it should be removed before decoding.
    
  • 解决

    在unmarshal之前将服务器返回的body处理一下:

     // Or []byte{239, 187, 191}
    body = bytes.TrimPrefix(body, []byte("\xef\xbb\xbf"))
    

相关文章

网友评论

    本文标题:go http 请求解析body err: invalid ch

    本文链接:https://www.haomeiwen.com/subject/tpugxltx.html