將編碼字符串添加到 http 響應(yīng)似乎用 !F(MISSING) 替換了一些字符。如何防止?輸出:{"encodedText":"M6c8RqL61nMFy%!F(MISSING)hQmciSYrh9ZXgVFVjO"}代碼:package mainimport ( "encoding/json" "fmt" "net/http" "net/url")type EncodeResult struct { EncodedText string `json:"encodedText"`}func main() { http.HandleFunc("/encodedString", encodedString) _ = http.ListenAndServe(":8080", nil)}func encodedString(w http.ResponseWriter, r *http.Request) { inputString := "M6c8RqL61nMFy/hQmciSYrh9ZXgVFVjO" er := EncodeResult{url.QueryEscape(inputString)} response, _ := json.Marshal(er) w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, string(response))}
如何在 http 響應(yīng)正文中返回編碼字符串?
慕碼人8056858
2021-08-23 16:36:34