zoukankan      html  css  js  c++  java
  • 9.9 重定向

    package main
    
    import (
    	"fmt"
    	"log"
    	"net/http"
    )
    
    func main() {
    	log.Println("Server is starting...")
    
    	http.Handle("/secured/handle", http.RedirectHandler("/login", http.StatusTemporaryRedirect))
    	http.HandleFunc("/secured/hadlefunc", func(w http.ResponseWriter, r *http.Request) {
    		http.Redirect(w, r, "/login", http.StatusTemporaryRedirect)
    	})
    	http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
    		fmt.Fprintf(w, "Welcome user! Please login!
    ")
    	})
    	if err := http.ListenAndServe(":8080", nil); err != nil {
    		panic(err)
    	}
    }
    
    /*
    ➜  recipe08 curl -v -L http://127.0.0.1:8080/secured/handle
    *   Trying 127.0.0.1...
    * TCP_NODELAY set
    * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
    > GET /secured/handle HTTP/1.1
    > Host: 127.0.0.1:8080
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 307 Temporary Redirect
    < Location: /login
    < Date: Mon, 26 Mar 2018 16:12:53 GMT
    < Content-Length: 42
    < Content-Type: text/html; charset=utf-8
    <
    * Ignoring the response-body
    * Connection #0 to host 127.0.0.1 left intact
    * Issue another request to this URL: 'http://127.0.0.1:8080/login'
    * Found bundle for host 127.0.0.1: 0x7f95e9611990 [can pipeline]
    * Re-using existing connection! (#0) with host 127.0.0.1
    * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
    > GET /login HTTP/1.1
    > Host: 127.0.0.1:8080
    > User-Agent: curl/7.54.0
    > Accept: */*
    >
    < HTTP/1.1 200 OK
    < Date: Mon, 26 Mar 2018 16:12:53 GMT
    < Content-Length: 28
    < Content-Type: text/plain; charset=utf-8
    <
    Welcome user! Please login!
    * Connection #0 to host 127.0.0.1 left intact
    
     */
    
    
  • 相关阅读:
    pandas笔记
    MongoDB分片集群技术
    MongoDB基本操作
    linux MongoDB安装配置
    MongoDB入门
    introJs用法及在webkit内核浏览器的一个报错
    日常ie兼容问题(持续整理)
    浅谈connect,withRouter,history,useState,useEffect
    node环境配置
    小程序之签到
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8654992.html
Copyright © 2011-2022 走看看