本文整理匯總了Golang中http.URLEscape函數的典型用法代碼示例。如果您正苦於以下問題:Golang URLEscape函數的具體用法?Golang URLEscape怎麽用?Golang URLEscape使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了URLEscape函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: writeCookies
// writeCookies writes the wire representation of the cookies
// to w. Each cookie is written on a separate "Cookie: " line.
// This choice is made because HTTP parsers tend to have a limit on
// line-length, so it seems safer to place cookies on separate lines.
func writeCookies(w io.Writer, kk []*http.Cookie) os.Error {
lines := make([]string, 0, len(kk))
var b bytes.Buffer
for _, c := range kk {
b.Reset()
n := c.Name
// TODO(petar): c.Value (below) should be unquoted if it is recognized as quoted
fmt.Fprintf(&b, "%s=%s", http.CanonicalHeaderKey(n), c.Value)
if len(c.Path) > 0 {
fmt.Fprintf(&b, "; $Path=%s", http.URLEscape(c.Path))
}
if len(c.Domain) > 0 {
fmt.Fprintf(&b, "; $Domain=%s", http.URLEscape(c.Domain))
}
if c.HttpOnly {
fmt.Fprintf(&b, "; $HttpOnly")
}
lines = append(lines, "Cookie: "+b.String()+"\r\n")
}
sort.Strings(lines)
for _, l := range lines {
if _, err := io.WriteString(w, l); err != nil {
return err
}
}
return nil
}
示例2: Request
func (t *Tracker) Request(uploaded int, downloaded int, left int, status string) (peers *list.List, err os.Error) {
err = nil
url := fmt.Sprint(t.url,
"?",
"info_hash=", http.URLEscape(t.infoHash),
"&peer_id=", http.URLEscape(t.peerId),
"&port=", http.URLEscape(t.port),
"&uploaded=", strconv.Itoa(uploaded),
"&downloaded=", strconv.Itoa(downloaded),
"&left=", strconv.Itoa(left),
"&status=", http.URLEscape(status))
println(url)
response, _, err := http.Get(url)
if err != nil {
return
}
if response.StatusCode != http.StatusOK {
err = os.NewError("http error")
}
buf := new(bencode.BeString)
resReader := bufio.NewReader(response.Body)
be, err := buf.Decode(resReader)
if err != nil {
return
}
if be.Betype != bencode.Bedict {
err = os.NewError("unexpected response from tracker")
return
}
if failure, ok := be.Bedict["failure reason"]; !ok {
err = os.NewError("unexpected response from tracker")
return
} else {
print(failure)
return
}
if interval, ok := be.Bedict["interval"]; !ok {
err = os.NewError("unexpected response from tracker")
return
} else {
t.interval, err = strconv.Atoi(interval.Bestr)
}
if _, ok := be.Bedict["peers"]; !ok {
err = os.NewError("unexpected response from tracker")
return
}
list := list.New()
for i := range be.Bedict["peers"].Belist.Iter() {
if i.(*bencode.BeNode).Betype == bencode.Bedict {
list.PushFront(i.(*bencode.BeNode).Bedict)
} else {
err = os.NewError("unexpected response from tracker")
return
}
}
peers = list
return
}
示例3: Urlencode
func Urlencode(data map[string]string) string {
var buf bytes.Buffer
for k, v := range data {
buf.WriteString(http.URLEscape(k))
buf.WriteByte('=')
buf.WriteString(http.URLEscape(v))
buf.WriteByte('&')
}
s := buf.String()
return s[0 : len(s)-1]
}
示例4: toQuery
func toQuery(params map[string]string) string {
buf := bytes.NewBuffer(nil)
flag := false
for key, val := range params {
if flag {
buf.WriteString("&" + key + "=" + http.URLEscape(val))
} else {
flag = true
buf.WriteString(key + "=" + http.URLEscape(val))
}
}
return buf.String()
}
示例5: remoteSearch
func remoteSearch(query string) (res *http.Response, err os.Error) {
search := "/search?f=text&q=" + http.URLEscape(query)
// list of addresses to try
var addrs []string
if *serverAddr != "" {
// explicit server address - only try this one
addrs = []string{*serverAddr}
} else {
addrs = []string{
defaultAddr,
"golang.org",
}
}
// remote search
for _, addr := range addrs {
url := "http://" + addr + search
res, err = http.Get(url)
if err == nil && res.StatusCode == http.StatusOK {
break
}
}
if err == nil && res.StatusCode != http.StatusOK {
err = os.NewError(res.Status)
}
return
}
示例6: escape
func escape(str string) string {
str = http.URLEscape(str)
str = strings.Replace(str, ":", "%3A", -1)
str = strings.Replace(str, "/", "%2F", -1)
return str
}
示例7: tf
func tf(c *http.Conn, b string, e string, n int, y int, s string) int {
var qs string
var ntf int = 0
if len(s) < 1 {
return ntf
}
if s[0] == '#' && len(s) > 1 {
qs = s
} else {
qs = "from:" + s
}
r, _, err := http.Get(fmt.Sprintf(queryURI,
qformat, http.URLEscape(qs), b, e, n))
if err == nil {
if r.StatusCode == http.StatusOK {
ntf = readjson(c, r.Body, b, e, y)
} else {
fmt.Printf("Twitter is unable to search for %s (%s)\n", s, r.Status)
}
r.Body.Close()
} else {
fmt.Printf("%v\n", err)
}
return ntf
}
示例8: StatusesUpdate
func (c *Client) StatusesUpdate(status string, replyId uint64) (err os.Error) {
var params string
if status == "" {
return os.NewError("must need \"status\" parameter.")
}
params = addParam(params, "status", http.URLEscape(status))
if replyId != 0 {
params = addParam(params, "in_reply_to_status_id", fmt.Sprintf("%d", replyId))
}
url := c.makeAuthURL(statusesUpdate, params)
res, err := http.Post(url, "", bytes.NewBufferString(""))
if err != nil {
return err
}
if res.Status != "200 OK" {
return os.NewError("Request failed")
}
return nil
}
示例9: TestSuccessfulTokenRequest
func TestSuccessfulTokenRequest(t *testing.T) {
c := basicConsumer()
m := newMocks(t)
m.install(c)
m.httpClient.ExpectGet(
"http://www.mrjon.es/requesttoken",
map[string]string{
"oauth_callback": http.URLEscape("http://www.mrjon.es/callback"),
"oauth_consumer_key": "consumerkey",
"oauth_nonce": "2",
"oauth_signature": "MOCK_SIGNATURE",
"oauth_signature_method": "HMAC-SHA1",
"oauth_timestamp": "1",
"oauth_version": "1.0",
},
"oauth_token=TOKEN&oauth_token_secret=SECRET")
token, url, err := c.GetRequestTokenAndUrl("http://www.mrjon.es/callback")
if err != nil {
t.Fatal(err)
}
assertEq(t, "TOKEN", token.Token)
assertEq(t, "SECRET", token.Secret)
assertEq(t, "consumersecret&", m.signer.UsedKey)
assertEq(t, "http://www.mrjon.es/authorizetoken?oauth_token=TOKEN", url)
}
示例10: downloadBlob
func (self *Federation) downloadBlob(rawurl, blobref string) (dependencies []string, err os.Error) {
// Get the blob
var client http.Client
req, err := client.Get(rawurl + "?blobref=" + http.URLEscape(blobref))
if err != nil {
return nil, err
}
// TODO: Improve for large files
blob, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Printf("Error reading request body")
return nil, err
}
log.Printf("Downloaded %v\n", string(blob))
req.Body.Close()
self.store.StoreBlob(blob, "")
// Check whether the retrieved blob is a schema blob
mimetype := grapher.MimeType(blob)
if mimetype == "application/x-lightwave-schema" {
var schema depSchema
err = json.Unmarshal(blob, &schema)
if err != nil {
log.Printf("Malformed schema blob: %v\n", err)
return nil, err
}
dependencies = schema.Dependencies
}
return
}
示例11: handleLogout
func handleLogout(w http.ResponseWriter, r *http.Request) {
c = appengine.NewContext(r)
returnURL := "/"
// parse form
err := r.ParseForm()
if err != nil {
serveError(c, w, err)
return
}
if r.FormValue("continue") != "" {
returnURL = r.FormValue("continue")
}
if useOpenID {
// adjust returnURL to bring us back to a local user login form
laterReturnUrl := returnURL
returnURL = "/Login/?chooseLogin=1&continue=" + http.URLEscape(laterReturnUrl)
}
// redirect to google logout (for OpenID as well, or else we won't be locally logged out)
lourl, err := user.LogoutURL(c, returnURL)
if err != nil {
c.Errorf("handleLogout: error getting LogoutURL")
}
c.Debugf("handleLogout: redirecting to logoutURL=%v", lourl)
http.Redirect(w, r, lourl, http.StatusFound)
return
}
示例12: main
// for each search term on the commandline, create a photo grid
func main() {
for i := 1; i < len(os.Args); i++ {
canvas.Start(width, height)
canvas.Rect(0, 0, width, height, "fill:black")
fs(http.URLEscape(os.Args[i]))
canvas.End()
}
}
示例13: addQueryVariables
func addQueryVariables(url string, variables map[string]string) string {
var addition string
newUrl := url
i := 0
for key, value := range variables {
if i == 0 {
addition = fmt.Sprintf("?%s=%s", key, http.URLEscape(value))
} else {
addition = fmt.Sprintf("&%s=%s", key, http.URLEscape(value))
}
newUrl += addition
i++
}
return newUrl
}
示例14: FormEncodedBytes
// FormEncodedBytes returns a buffer containing the URL form encoding of the
// map.
func (m Values) FormEncodedBytes() []byte {
var b bytes.Buffer
sep := false
for key, values := range m {
escapedKey := http.URLEscape(key)
for _, value := range values {
if sep {
b.WriteByte('&')
} else {
sep = true
}
b.WriteString(escapedKey)
b.WriteByte('=')
b.WriteString(http.URLEscape(value))
}
}
return b.Bytes()
}
示例15: TweetJson
func TweetJson(client *Client, message string) (responseStr string, err os.Error) {
message = http.URLEscape(message)
var form = map[string][]string{
"status": []string{message},
}
// send request
responseStr, err = send(URLSendTweet, "POST", form, client, "status="+message)
return
}