我正在尝试向运行PHP应用程序的端口8080上的localhost发送一个post请求.
卷曲工作正常:
curl --data "key=asdf" http://localhost:8080/
Run Code Online (Sandbox Code Playgroud)
但在Go中我收到以下错误:
Post http://localhost:8080: dial tcp 127.0.0.1:8080: connection refused
Run Code Online (Sandbox Code Playgroud)
这是代码:
func submitForm(value string){
resp, err := http.PostForm("http://localhost:8080", url.Values{"key": {value}})
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("status = ",resp.Status)
}
submitForm("asdf")
Run Code Online (Sandbox Code Playgroud)
我使用httpry监控http流量,我发现没有生成http请求,但有一些包:
4 packets received, 0 packets dropped, 0 http packets parsed
Run Code Online (Sandbox Code Playgroud)
更多事实:
我使用PHP的内置Web服务器.使用此命令启动服务器:
php -S localhost:8080