如何获取完整的HTTP请求行?

huangapple go评论85阅读模式
英文:

how do I get the entire http request line?

问题

我正在尝试处理一个格式奇怪的请求

https://explorer.ether.cards/#/founder/1

目前在本地主机上进行测试

http://localhost:9009/#/founder/1

有没有办法提取/founder/1

我已经尝试了默认和自定义的muxes,但找不到提取值的方法。

英文:

I am trying to handle a request that has a strange formatting

https://explorer.ether.cards/#/founder/1

currently testing on localhost as

http://localhost:9009/#/founder/1

Is there any way to extract the /founder/1 ?

I have tried the default and custom muxes but cannot find any way to extract the values.

答案1

得分: 2

使用Request.RequestURI字段来获取从网络读取的HTTP请求URI。根据你的需求解析该值。

#/founder/1是一个片段。片段不是HTTP请求URI的一部分,客户端不会将片段发送给服务器。

要在服务器上访问/founder/1,请将该值移动到路径或查询参数中。

英文:

Use the Request.RequestURI field to get the HTTP request URI as read from the network. Parse the value as needed by your requirements.

#/founder/1 Is a fragment. Fragments are not part of the HTTP request URI and are not sent to the server by clients.

To access /founder/1 on the server, move the value to the path or a query parameter.

答案2

得分: 1

在URL中,#后面的任何内容都被视为URL片段。这里请求URL的设计不正确,因为#被用作请求路径的一部分,使/founder/1成为URL片段。URL片段只是一个浏览器端的概念,浏览器不会将URL片段发送到服务器端。

简而言之,在服务器端无法捕获/founder/1

英文:

Anything after # in the URL is considered as the URL fragment.
The design of request URL is not correct here because # is being used here as a part of request path making /founder/1 a URL fragment. URL fragment is only a browser-side concept and browsers do not send URL fragment to the server side.

So in short, you cannot capture /founder/1 on the server side.

huangapple
  • 本文由 发表于 2021年7月20日 04:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/68446400.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定