将一个编码的字符串添加到http反应中似乎用!F(MISSING)替换某些字符。那是如何被阻止的?如何返回http响应正文中的编码字符串?
输出:
{ “encodedText”: “M6c8RqL61nMFy%F(丢失)hQmciSYrh9ZXgVFVjO”}
代码:
package main
import (
"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))
}
谢谢查理,我看到了问题。任何修复建议? :) – 2014-10-17 14:44:21