且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在http响应正文中返回编码的字符串?

更新时间:2021-08-19 22:18:49

您正在使用转义的值 M6c8RqL61nMFy%2 FhQmciSYrh9ZXgVFVjO作为此行上的格式字符串:

You are using the escaped value "M6c8RqL61nMFy%2FhQmciSYrh9ZXgVFVjO " as a format string on this line:

fmt.Fprintf(w, string(response))

Fprintf尝试格式化动词%2F的自变量。没有参数,因此Fprintf为动词打印%!F(MISSING)。

Fprintf attempts to format an argument for the verb "%2F". There is no argument, so Fprintf prints "%!F(MISSING)" for the verb.

解决方法是不要将输出用作格式字符串。因为写入响应时不需要任何格式,所以将最后一行更改为:

The fix is to not use the output as a format string. Because you don't need any formatting when writing to the response, change the last line to:

w.Write(response)