1、增加cookiejar支持
2、增加Setting结构,便于统一设置请求参数 3、增加服务端测试php脚本
Showing
3 changed files
with
174 additions
and
40 deletions
| ... | @@ -17,21 +17,44 @@ import ( | ... | @@ -17,21 +17,44 @@ import ( |
| 17 | "net" | 17 | "net" |
| 18 | "net/http" | 18 | "net/http" |
| 19 | "net/http/httputil" | 19 | "net/http/httputil" |
| 20 | "net/http/cookiejar" | ||
| 20 | "net/url" | 21 | "net/url" |
| 21 | "os" | 22 | "os" |
| 22 | "strings" | 23 | "strings" |
| 23 | "time" | 24 | "time" |
| 25 | "sync" | ||
| 24 | ) | 26 | ) |
| 25 | 27 | ||
| 26 | var defaultUserAgent = "beegoServer" | 28 | var defaultSetting = BeegoHttpSettings{false, "beegoServer", 60 * time.Second, 60 * time.Second, nil, nil, nil, false} |
| 29 | var defaultCookieJar http.CookieJar | ||
| 30 | var settingMutex sync.Mutex | ||
| 31 | |||
| 32 | // createDefaultCookieJar creates a global cookiejar to store cookies. | ||
| 33 | func createDefaultCookie() { | ||
| 34 | settingMutex.Lock() | ||
| 35 | defer settingMutex.Unlock() | ||
| 36 | defaultCookieJar, _ = cookiejar.New(nil) | ||
| 37 | } | ||
| 38 | |||
| 39 | // Overwrite default settings | ||
| 40 | func SetDefaultSetting(setting BeegoHttpSettings) { | ||
| 41 | settingMutex.Lock() | ||
| 42 | defer settingMutex.Unlock() | ||
| 43 | defaultSetting = setting | ||
| 44 | if defaultSetting.ConnectTimeout == 0 { | ||
| 45 | defaultSetting.ConnectTimeout = 60*time.Second | ||
| 46 | } | ||
| 47 | if defaultSetting.ReadWriteTimeout == 0 { | ||
| 48 | defaultSetting.ReadWriteTimeout = 60*time.Second | ||
| 49 | } | ||
| 50 | } | ||
| 27 | 51 | ||
| 28 | // Get returns *BeegoHttpRequest with GET method. | 52 | // Get returns *BeegoHttpRequest with GET method. |
| 29 | func Get(url string) *BeegoHttpRequest { | 53 | func Get(url string) *BeegoHttpRequest { |
| 30 | var req http.Request | 54 | var req http.Request |
| 31 | req.Method = "GET" | 55 | req.Method = "GET" |
| 32 | req.Header = http.Header{} | 56 | req.Header = http.Header{} |
| 33 | req.Header.Set("User-Agent", defaultUserAgent) | 57 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } |
| 34 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} | ||
| 35 | } | 58 | } |
| 36 | 59 | ||
| 37 | // Post returns *BeegoHttpRequest with POST method. | 60 | // Post returns *BeegoHttpRequest with POST method. |
| ... | @@ -39,8 +62,7 @@ func Post(url string) *BeegoHttpRequest { | ... | @@ -39,8 +62,7 @@ func Post(url string) *BeegoHttpRequest { |
| 39 | var req http.Request | 62 | var req http.Request |
| 40 | req.Method = "POST" | 63 | req.Method = "POST" |
| 41 | req.Header = http.Header{} | 64 | req.Header = http.Header{} |
| 42 | req.Header.Set("User-Agent", defaultUserAgent) | 65 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } |
| 43 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} | ||
| 44 | } | 66 | } |
| 45 | 67 | ||
| 46 | // Put returns *BeegoHttpRequest with PUT method. | 68 | // Put returns *BeegoHttpRequest with PUT method. |
| ... | @@ -48,8 +70,7 @@ func Put(url string) *BeegoHttpRequest { | ... | @@ -48,8 +70,7 @@ func Put(url string) *BeegoHttpRequest { |
| 48 | var req http.Request | 70 | var req http.Request |
| 49 | req.Method = "PUT" | 71 | req.Method = "PUT" |
| 50 | req.Header = http.Header{} | 72 | req.Header = http.Header{} |
| 51 | req.Header.Set("User-Agent", defaultUserAgent) | 73 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } |
| 52 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} | ||
| 53 | } | 74 | } |
| 54 | 75 | ||
| 55 | // Delete returns *BeegoHttpRequest DELETE GET method. | 76 | // Delete returns *BeegoHttpRequest DELETE GET method. |
| ... | @@ -57,8 +78,7 @@ func Delete(url string) *BeegoHttpRequest { | ... | @@ -57,8 +78,7 @@ func Delete(url string) *BeegoHttpRequest { |
| 57 | var req http.Request | 78 | var req http.Request |
| 58 | req.Method = "DELETE" | 79 | req.Method = "DELETE" |
| 59 | req.Header = http.Header{} | 80 | req.Header = http.Header{} |
| 60 | req.Header.Set("User-Agent", defaultUserAgent) | 81 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } |
| 61 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} | ||
| 62 | } | 82 | } |
| 63 | 83 | ||
| 64 | // Head returns *BeegoHttpRequest with HEAD method. | 84 | // Head returns *BeegoHttpRequest with HEAD method. |
| ... | @@ -66,8 +86,19 @@ func Head(url string) *BeegoHttpRequest { | ... | @@ -66,8 +86,19 @@ func Head(url string) *BeegoHttpRequest { |
| 66 | var req http.Request | 86 | var req http.Request |
| 67 | req.Method = "HEAD" | 87 | req.Method = "HEAD" |
| 68 | req.Header = http.Header{} | 88 | req.Header = http.Header{} |
| 69 | req.Header.Set("User-Agent", defaultUserAgent) | 89 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, defaultSetting } |
| 70 | return &BeegoHttpRequest{url, &req, map[string]string{}, map[string]string{}, false, 60 * time.Second, 60 * time.Second, nil, nil, nil} | 90 | } |
| 91 | |||
| 92 | // BeegoHttpSettings | ||
| 93 | type BeegoHttpSettings struct{ | ||
| 94 | ShowDebug bool | ||
| 95 | UserAgent string | ||
| 96 | ConnectTimeout time.Duration | ||
| 97 | ReadWriteTimeout time.Duration | ||
| 98 | TlsClientConfig *tls.Config | ||
| 99 | Proxy func(*http.Request) (*url.URL, error) | ||
| 100 | Transport http.RoundTripper | ||
| 101 | EnableCookie bool | ||
| 71 | } | 102 | } |
| 72 | 103 | ||
| 73 | // BeegoHttpRequest provides more useful methods for requesting one url than http.Request. | 104 | // BeegoHttpRequest provides more useful methods for requesting one url than http.Request. |
| ... | @@ -76,30 +107,43 @@ type BeegoHttpRequest struct { | ... | @@ -76,30 +107,43 @@ type BeegoHttpRequest struct { |
| 76 | req *http.Request | 107 | req *http.Request |
| 77 | params map[string]string | 108 | params map[string]string |
| 78 | files map[string]string | 109 | files map[string]string |
| 79 | showdebug bool | 110 | setting BeegoHttpSettings |
| 80 | connectTimeout time.Duration | 111 | } |
| 81 | readWriteTimeout time.Duration | 112 | |
| 82 | tlsClientConfig *tls.Config | 113 | // Change request settings |
| 83 | proxy func(*http.Request) (*url.URL, error) | 114 | func (b *BeegoHttpRequest) Setting(setting BeegoHttpSettings) *BeegoHttpRequest { |
| 84 | transport http.RoundTripper | 115 | b.setting = setting |
| 116 | return b | ||
| 117 | } | ||
| 118 | |||
| 119 | // SetEnableCookie sets enable/disable cookiejar | ||
| 120 | func (b *BeegoHttpRequest) SetEnableCookie(enable bool) *BeegoHttpRequest { | ||
| 121 | b.setting.EnableCookie = enable | ||
| 122 | return b | ||
| 123 | } | ||
| 124 | |||
| 125 | // SetUserAgent sets User-Agent header field | ||
| 126 | func (b *BeegoHttpRequest) SetAgent(useragent string) *BeegoHttpRequest { | ||
| 127 | b.setting.UserAgent = useragent | ||
| 128 | return b | ||
| 85 | } | 129 | } |
| 86 | 130 | ||
| 87 | // Debug sets show debug or not when executing request. | 131 | // Debug sets show debug or not when executing request. |
| 88 | func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest { | 132 | func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest { |
| 89 | b.showdebug = isdebug | 133 | b.setting.ShowDebug = isdebug |
| 90 | return b | 134 | return b |
| 91 | } | 135 | } |
| 92 | 136 | ||
| 93 | // SetTimeout sets connect time out and read-write time out for BeegoRequest. | 137 | // SetTimeout sets connect time out and read-write time out for BeegoRequest. |
| 94 | func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHttpRequest { | 138 | func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHttpRequest { |
| 95 | b.connectTimeout = connectTimeout | 139 | b.setting.ConnectTimeout = connectTimeout |
| 96 | b.readWriteTimeout = readWriteTimeout | 140 | b.setting.ReadWriteTimeout = readWriteTimeout |
| 97 | return b | 141 | return b |
| 98 | } | 142 | } |
| 99 | 143 | ||
| 100 | // SetTLSClientConfig sets tls connection configurations if visiting https url. | 144 | // SetTLSClientConfig sets tls connection configurations if visiting https url. |
| 101 | func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest { | 145 | func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest { |
| 102 | b.tlsClientConfig = config | 146 | b.setting.TlsClientConfig = config |
| 103 | return b | 147 | return b |
| 104 | } | 148 | } |
| 105 | 149 | ||
| ... | @@ -134,7 +178,7 @@ func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest { | ... | @@ -134,7 +178,7 @@ func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest { |
| 134 | 178 | ||
| 135 | // Set transport to | 179 | // Set transport to |
| 136 | func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpRequest { | 180 | func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpRequest { |
| 137 | b.transport = transport | 181 | b.setting.Transport = transport |
| 138 | return b | 182 | return b |
| 139 | } | 183 | } |
| 140 | 184 | ||
| ... | @@ -146,7 +190,7 @@ func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpR | ... | @@ -146,7 +190,7 @@ func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpR |
| 146 | // return u, nil | 190 | // return u, nil |
| 147 | // } | 191 | // } |
| 148 | func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHttpRequest { | 192 | func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHttpRequest { |
| 149 | b.proxy = proxy | 193 | b.setting.Proxy = proxy |
| 150 | return b | 194 | return b |
| 151 | } | 195 | } |
| 152 | 196 | ||
| ... | @@ -194,9 +238,9 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -194,9 +238,9 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 194 | 238 | ||
| 195 | if b.req.Method == "GET" && len(paramBody) > 0 { | 239 | if b.req.Method == "GET" && len(paramBody) > 0 { |
| 196 | if strings.Index(b.url, "?") != -1 { | 240 | if strings.Index(b.url, "?") != -1 { |
| 197 | b.url += "&" + paramBody | 241 | b.url += "&"+paramBody |
| 198 | } else { | 242 | } else { |
| 199 | b.url = b.url + "?" + paramBody | 243 | b.url = b.url+"?"+paramBody |
| 200 | } | 244 | } |
| 201 | } else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 { | 245 | } else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 { |
| 202 | if len(b.files) > 0 { | 246 | if len(b.files) > 0 { |
| ... | @@ -234,7 +278,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -234,7 +278,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 234 | 278 | ||
| 235 | url, err := url.Parse(b.url) | 279 | url, err := url.Parse(b.url) |
| 236 | if url.Scheme == "" { | 280 | if url.Scheme == "" { |
| 237 | b.url = "http://" + b.url | 281 | b.url = "http://"+b.url |
| 238 | url, err = url.Parse(b.url) | 282 | url, err = url.Parse(b.url) |
| 239 | } | 283 | } |
| 240 | if err != nil { | 284 | if err != nil { |
| ... | @@ -242,7 +286,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -242,7 +286,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 242 | } | 286 | } |
| 243 | 287 | ||
| 244 | b.req.URL = url | 288 | b.req.URL = url |
| 245 | if b.showdebug { | 289 | if b.setting.ShowDebug { |
| 246 | dump, err := httputil.DumpRequest(b.req, true) | 290 | dump, err := httputil.DumpRequest(b.req, true) |
| 247 | if err != nil { | 291 | if err != nil { |
| 248 | println(err.Error()) | 292 | println(err.Error()) |
| ... | @@ -250,32 +294,47 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { | ... | @@ -250,32 +294,47 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) { |
| 250 | println(string(dump)) | 294 | println(string(dump)) |
| 251 | } | 295 | } |
| 252 | 296 | ||
| 253 | trans := b.transport | 297 | trans := b.setting.Transport |
| 254 | 298 | ||
| 255 | if trans == nil { | 299 | if trans == nil { |
| 256 | // create default transport | 300 | // create default transport |
| 257 | trans = &http.Transport{ | 301 | trans = &http.Transport{ |
| 258 | TLSClientConfig: b.tlsClientConfig, | 302 | TLSClientConfig: b.setting.TlsClientConfig, |
| 259 | Proxy: b.proxy, | 303 | Proxy: b.setting.Proxy, |
| 260 | Dial: TimeoutDialer(b.connectTimeout, b.readWriteTimeout), | 304 | Dial: TimeoutDialer(b.setting.ConnectTimeout, b.setting.ReadWriteTimeout), |
| 261 | } | 305 | } |
| 262 | } else { | 306 | } else { |
| 263 | // if b.transport is *http.Transport then set the settings. | 307 | // if b.transport is *http.Transport then set the settings. |
| 264 | if t, ok := trans.(*http.Transport); ok { | 308 | if t, ok := trans.(*http.Transport); ok { |
| 265 | if t.TLSClientConfig == nil { | 309 | if t.TLSClientConfig == nil { |
| 266 | t.TLSClientConfig = b.tlsClientConfig | 310 | t.TLSClientConfig = b.setting.TlsClientConfig |
| 267 | } | 311 | } |
| 268 | if t.Proxy == nil { | 312 | if t.Proxy == nil { |
| 269 | t.Proxy = b.proxy | 313 | t.Proxy = b.setting.Proxy |
| 270 | } | 314 | } |
| 271 | if t.Dial == nil { | 315 | if t.Dial == nil { |
| 272 | t.Dial = TimeoutDialer(b.connectTimeout, b.readWriteTimeout) | 316 | t.Dial = TimeoutDialer(b.setting.ConnectTimeout, b.setting.ReadWriteTimeout) |
| 273 | } | 317 | } |
| 274 | } | 318 | } |
| 275 | } | 319 | } |
| 276 | 320 | ||
| 321 | var jar http.CookieJar | ||
| 322 | if b.setting.EnableCookie { | ||
| 323 | if defaultCookieJar == nil { | ||
| 324 | createDefaultCookie() | ||
| 325 | } | ||
| 326 | jar = defaultCookieJar | ||
| 327 | }else { | ||
| 328 | jar = nil | ||
| 329 | } | ||
| 330 | |||
| 277 | client := &http.Client{ | 331 | client := &http.Client{ |
| 278 | Transport: trans, | 332 | Transport: trans, |
| 333 | Jar:jar, | ||
| 334 | } | ||
| 335 | |||
| 336 | if b.setting.UserAgent != "" { | ||
| 337 | b.req.Header.Set("User-Agent", b.setting.UserAgent) | ||
| 279 | } | 338 | } |
| 280 | 339 | ||
| 281 | resp, err := client.Do(b.req) | 340 | resp, err := client.Do(b.req) | ... | ... |
| 1 | // Beego (http://beego.me/) | 1 | // Beego (http://localhost/httplib_test.php) |
| 2 | // @description beego is an open-source, high-performance web framework for the Go programming language. | 2 | // @description beego is an open-source, high-performance web framework for the Go programming language. |
| 3 | // @link http://github.com/astaxie/beego for the canonical source repository | 3 | // @link http://github.com/astaxie/beego for the canonical source repository |
| 4 | // @license http://github.com/astaxie/beego/blob/master/LICENSE | 4 | // @license http://github.com/astaxie/beego/blob/master/LICENSE |
| ... | @@ -7,13 +7,13 @@ | ... | @@ -7,13 +7,13 @@ |
| 7 | package httplib | 7 | package httplib |
| 8 | 8 | ||
| 9 | import ( | 9 | import ( |
| 10 | "testing" | ||
| 10 | "fmt" | 11 | "fmt" |
| 11 | "io/ioutil" | 12 | "io/ioutil" |
| 12 | "testing" | ||
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | func TestGetUrl(t *testing.T) { | 15 | func TestGetUrl(t *testing.T) { |
| 16 | resp, err := Get("http://beego.me/").Debug(true).Response() | 16 | resp, err := Get("http://localhost/httplib_test.php").Debug(true).Response() |
| 17 | if err != nil { | 17 | if err != nil { |
| 18 | t.Fatal(err) | 18 | t.Fatal(err) |
| 19 | } | 19 | } |
| ... | @@ -29,7 +29,7 @@ func TestGetUrl(t *testing.T) { | ... | @@ -29,7 +29,7 @@ func TestGetUrl(t *testing.T) { |
| 29 | t.Fatal("data is no") | 29 | t.Fatal("data is no") |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | str, err := Get("http://beego.me/").String() | 32 | str, err := Get("http://localhost/httplib_test.php").String() |
| 33 | if err != nil { | 33 | if err != nil { |
| 34 | t.Fatal(err) | 34 | t.Fatal(err) |
| 35 | } | 35 | } |
| ... | @@ -39,13 +39,62 @@ func TestGetUrl(t *testing.T) { | ... | @@ -39,13 +39,62 @@ func TestGetUrl(t *testing.T) { |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | func TestPost(t *testing.T) { | 41 | func TestPost(t *testing.T) { |
| 42 | b := Post("http://beego.me/").Debug(true) | 42 | b := Post("http://localhost/httplib_test.php").Debug(true) |
| 43 | b.Param("username", "astaxie") | 43 | b.Param("username", "astaxie") |
| 44 | b.Param("password", "hello") | 44 | b.Param("password", "hello") |
| 45 | b.PostFile("uploadfile", "httplib.go") | 45 | b.PostFile("uploadfile", "httplib_test.php") |
| 46 | str, err := b.String() | 46 | str, err := b.String() |
| 47 | if err != nil { | 47 | if err != nil { |
| 48 | t.Fatal(err) | 48 | t.Fatal(err) |
| 49 | } | 49 | } |
| 50 | fmt.Println(str) | 50 | fmt.Println(str) |
| 51 | } | 51 | } |
| 52 | |||
| 53 | func TestSimpleGetString(t *testing.T) { | ||
| 54 | fmt.Println("TestSimpleGetString==========================================") | ||
| 55 | html, err := Get("http://localhost/httplib_test.php").SetAgent("beegoooooo").String() | ||
| 56 | if err != nil { | ||
| 57 | t.Fatal(err) | ||
| 58 | } | ||
| 59 | fmt.Println(html) | ||
| 60 | fmt.Println("TestSimpleGetString==========================================") | ||
| 61 | } | ||
| 62 | |||
| 63 | func TestSimpleGetStringWithDefaultCookie(t *testing.T) { | ||
| 64 | fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") | ||
| 65 | html, err := Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() | ||
| 66 | if err != nil { | ||
| 67 | t.Fatal(err) | ||
| 68 | } | ||
| 69 | fmt.Println(html) | ||
| 70 | html, err = Get("http://localhost/httplib_test.php").SetEnableCookie(true).String() | ||
| 71 | if err != nil { | ||
| 72 | t.Fatal(err) | ||
| 73 | } | ||
| 74 | fmt.Println(html) | ||
| 75 | fmt.Println("TestSimpleGetStringWithDefaultCookie==========================================") | ||
| 76 | } | ||
| 77 | |||
| 78 | func TestDefaultSetting(t *testing.T) { | ||
| 79 | fmt.Println("TestDefaultSetting==========================================") | ||
| 80 | var def BeegoHttpSettings | ||
| 81 | def.EnableCookie = true | ||
| 82 | //def.ShowDebug = true | ||
| 83 | def.UserAgent = "UserAgent" | ||
| 84 | //def.ConnectTimeout = 60*time.Second | ||
| 85 | //def.ReadWriteTimeout = 60*time.Second | ||
| 86 | def.Transport = nil//http.DefaultTransport | ||
| 87 | SetDefaultSetting(def) | ||
| 88 | |||
| 89 | html, err := Get("http://localhost/httplib_test.php").String() | ||
| 90 | if err != nil { | ||
| 91 | t.Fatal(err) | ||
| 92 | } | ||
| 93 | fmt.Println(html) | ||
| 94 | html, err = Get("http://localhost/httplib_test.php").String() | ||
| 95 | if err != nil { | ||
| 96 | t.Fatal(err) | ||
| 97 | } | ||
| 98 | fmt.Println(html) | ||
| 99 | fmt.Println("TestDefaultSetting==========================================") | ||
| 100 | } | ... | ... |
httplib/httplib_test.php
0 → 100644
| 1 | <?php | ||
| 2 | session_id() or session_start(); | ||
| 3 | if (!isset($_SESSION['first_time'])) { | ||
| 4 | $_SESSION['first_time'] = time(); | ||
| 5 | } | ||
| 6 | $data = array(); | ||
| 7 | $HTTP = array(); | ||
| 8 | foreach ($_SERVER as $head => $value) { | ||
| 9 | if (strpos($head, "HTTP_") === 0) { | ||
| 10 | $HTTP[$head] = $value; | ||
| 11 | } | ||
| 12 | } | ||
| 13 | $data['HTTP'] = $HTTP; | ||
| 14 | $data['GET'] = $_GET; | ||
| 15 | $data['POST'] = $_POST; | ||
| 16 | $data['REQUEST'] = $_REQUEST; | ||
| 17 | $data['SESSION'] = $_SESSION; | ||
| 18 | $data['COOKIE'] = $_COOKIE; | ||
| 19 | $data['FILES'] = $_FILES; | ||
| 20 | $data['SERVER'] = $_SERVER; | ||
| 21 | $data['ENV'] = $_ENV; | ||
| 22 | |||
| 23 | //echo json_encode($data); | ||
| 24 | //echo "<pre>"; | ||
| 25 | print_r($data); | ||
| 26 | //echo "</pre>"; |
-
Please register or sign in to post a comment