有没有url.QueryEscape的例子和用法?为golang [英] Is there any example and usage of url.QueryEscape ? for golang
问题描述
如何在Go语言中理解并使用 url.QueryEscape
?
How to understand and use url.QueryEscape
, in Go language?
推荐答案
要理解 url.QueryEscape
的用法,您首先需要了解 url query string is。
To understand the usage of url.QueryEscape
, you first need to understand what a url query string is.
查询字符串是URL的一部分,其中包含可传递给Web应用程序的数据。这些数据需要进行编码,并使用 url.QueryEscape
完成此编码。它执行通常也称为网址编码的内容。
A query string is a part of URL that contains data that can be passed to web applications. This data needs to be encoded, and this encoding is done using url.QueryEscape
. It performs what is also commonly called URL encoding.
示例
假设我们有网页:
Let's say we have webpage:
http://mywebpage.com/thumbify
我们想要将图片url http://images.com/cat.png
传递给此Web应用程序。然后,这个网址需要如下所示:
And we want to pass an image url, http://images.com/cat.png
, to this web application. Then this url needs look something like this:
http://mywebpage.com/thumbify?image=http%3A%2F%2Fimages.com%2Fcat.png
在Go代码中,它看起来像这样:
In Go code, it would look like this:
package main
import (
"fmt"
"net/url"
)
func main() {
webpage := "http://mywebpage.com/thumbify"
image := "http://images.com/cat.png"
fmt.Println( webpage + "?image=" + url.QueryEscape(image))
}
这篇关于有没有url.QueryEscape的例子和用法?为golang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!