In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is the context module of context in beego. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Further encapsulation of request (Input) and response (Output) in HTTP requests. The context object is an encapsulation of Input and Output.
Input object
The specific methods are as follows:
Protocol gets the protocol requested by the user, such as HTTP/1.0
The RequestURI requested by the Uri user, such as / hi?id=1001
The URL address of the Url request, such as / hi
The site address requested by Site, the combination of scheme+doamin, such as http://beego.me
The scheme of the Scheme request, such as "http" or "https"
The domain name requested by Domain, such as beego.me
Domain name requested by Host, which is the same as domain
Method request method, standard HTTP request method, such as GET, POST, etc.
Is determines whether it is a method. For example, Is ("GET") returns true.
IsAjax determines whether it is an AJAX request. If it returns true, it does not return false.
IsSecure determines whether the current request is a HTTPS request, whether it returns true or false.
IsWebsocket determines whether the current request is a Websocket request, and if it returns true, whether it returns false
IsUpload determines whether a file is uploaded in the current request. True is returned, and false is returned.
IP returns the IP of the requesting user, and if the user strips the real IP layer by layer through the agent
Proxy returns all IP requested by the user agent
Refer returns the requested refer information
SubDomains returns the root domain name of the request domain. For example, if the request is blog.beego.me, call this function to return beego.me.
Port returns the requested port, for example, 8080
UserAgent returns the requested UserAgent, such as Mozilla/5.0 (Macintosh; Intel Mac OSX 109.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
Param can set parameters when setting the route. This is used to get those parameters, such as Param (": id"), which returns 12.
Query this function returns all data in Get and Post requests, similar to $_ REQUEST in PHP
If Header returns the corresponding header information, such as Header ("Accept-Language"), it returns the corresponding information zh-CN,zh;q=0.8,en;q=0.6 in the request header.
If Cookie returns the cookie data in the request, such as Cookie ("username"), you can get the corresponding value of username in the cookie information carried in the request header.
Session session is the information that the user can initialize. By default, the Session object in the session module of beego is used to obtain the data stored in the server.
Body returns the data in the request Body. For example, in API applications, many users send json packets directly, so the data cannot be obtained through the Query function, so the data must be obtained through this function. This function has been deleted after the beego1.5 version, and the data can be obtained through RequestBody.
GetData is used to obtain data from Data in Input.
SetData is used to set the value of Data in Input. The above GetData and this function are used to facilitate users to pass data to Controller in Filter for execution.
Output object
Output is an encapsulation for Response, which provides many convenient uses:
Header sets the output header information, such as Header ("Server", "beego")
Body sets the output content information, such as Body ([] byte ("astaxie"))
Cookie sets the output cookie information, such as Cookie ("sessionID", "beegoSessionID")
Json formats Data as Json, and then calls Body to output the data
Jsonp formats Data as Jsonp, and then calls Body to output the data
Xml formats Data as Xml, and then calls Body to output the data
Download passes in the file path, and then outputs the file to the user
ContentType sets the output ContentType
SetStatus sets the output status
Session sets the value saved on the server side, such as Session ("username", "astaxie"), so that users can read it the next time they use it.
According to status, IsCachable determines whether it is the state of the cache class.
According to status, IsEmpty determines whether the output is empty.
According to status, IsOk judges whether it is 200th or not.
According to status, IsSuccessful judges whether it is normal or not.
According to status, IsRedirect judges whether it is the status of jump class.
According to status, IsForbidden determines whether it is the state of a disabled class.
According to status, IsNotFound judges whether it is the status of resource class that cannot be found.
According to status, IsClientError determines whether it is the error status of the request client.
According to status, IsServerError determines whether it is a server-side error state.
About what the context module of context in beego is shared here, I hope the above content can be of some help to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.