#GO 客户端
client := &http.Client{}
req, err := http.NewRequest(
"POST",
"http://127.0.0.1/login/check",
nil,
)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
req.Body = ioutil.NopCloser(strings.NewReader("username=admin&password=123456"))
resp, _ := client.Do(req)
defer resp.Body.Close()
#PHP 服务端
file_get_contents("php://input") // 这里获取不到任何东西
#GO 服务端
func main() {
http.HandleFunc("/test", testHtpp)
http.ListenAndServe(":8085", nil)
}
func testHtpp(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
fmt.Println(string(body)) // 可以获取到 Body 的内容
}
请问为什么 php 获取不到任何内容