提取片段数据没有运气(foo
in http://domain.com/path#foo http://domain.com/path#foo)与标准http.Server
.
package main
import (
"fmt"
"net/http"
)
type Handler struct {
}
func (handler Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Path = \"%v\" Fragment = \"%v\"\n", r.URL.Path, r.URL.Fragment)
}
func main() {
var handler Handler
http.ListenAndServe(":30000", handler)
}
产生空片段http://127.0.0.1:30000/path#foo
:
Path = "/path" Fragment = ""
如何使用golang的内置函数获取片段数据http.Server
?
你不能。这不是 Go 的事情——URL 片段不会通过 HTTP 发送到服务器。它们只是一个浏览器概念。
Here is 相关问题 https://code.google.com/p/go/issues/detail?id=3805, where 的文档http.Request http://golang.org/pkg/net/http/#Request改为:
// For server requests the URL is parsed from the URI
// supplied on the Request-Line as stored in RequestURI. For
// most requests, fields other than Path and RawQuery will be
// empty. (See RFC 2616, Section 5.1.2)
如果出于某种原因您需要它,您可能可以将一些 JavaScript 串在一起以将该片段作为请求包含在请求中GET
参数什么的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)