How can I return an encoded string in an http response body?

前端 未结 2 1942
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 04:19

Adding an encoded string to an http resonse seems to replace some characters with !F(MISSING). How that that be prevented?

Output:

{\"encodedText\":\"M6c8RqL61nM

相关标签:
2条回答
  • 2021-01-26 04:54

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

    fmt.Fprintf(w, string(response))
    

    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)            
    
    0 讨论(0)
  • 2021-01-26 05:18

    It appears to be escaping it normally, can you paste some code?

    http://play.golang.org/p/rUEGn-KlTX

    package main
    
    import (
        "fmt"
        "net/url"
    )
    
    func main() {
    
        escape := url.QueryEscape("M6c8RqL61nMFy/hQmciSYrh9ZXgVFVjO")
    
        fmt.Println(escape)
    }
    
    0 讨论(0)
提交回复
热议问题