In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to solve the inconsistent value of Ajax accessing session and the difference between GET and POST in HTTP protocol? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Today, I encountered a problem when I was making a progress bar. I stored a counter in session. When I crawled a piece of data, this value was + 1, and then the receptionist got this value of session every 3 seconds. But the problem came out. Under FF, the values are all normal, but under IE, they are all the previous values. You can only get the latest session value when you re-open the page:
Here is the code for my proBar.jsp:
Function createXMLHttpRequest () {var xmlHttp; if (window.ActiveXObject) {xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");} else {xmlHttp = new XMLHttpRequest ();} return xmlHttp;} function btn_click () {var xmlHttp; xmlHttp = createXMLHttpRequest (); xmlHttp.onreadystatechange = processor; / / xmlHttp.open ("GET", "/ jbbs/servlet/ControlCrawl?method=getinforsize", true); xmlHttp.open ("POST", "/ jbbs/servlet/ControlCrawl?method=getinforsize", true) XmlHttp.send (null); function processor () {. }} var action=setInterval ("btn_click ();",); crawl progress:
Later, it was normal to change GET to POST.
PS: GET and POST about HTTP
Http defines different ways to interact with the server, the most basic of which is GET,POST,PUT,DELETE. The full name of URL is a resource descriptor, we can think of it as: a URL address, which is used to describe a resource on a network, and the GET,POST,PUT,DELETE in HTTP corresponds to the four operations of searching, changing, adding, and deleting the resource. At this point, you should have a general understanding that GET is generally used to obtain / query resource information, while POST is generally used to update resource information.
1. According to the HTTP specification, GET is used for information acquisition and should be secure and idempotent.
(1)。 The so-called security means that the operation is used to obtain information rather than modify it. In other words, GET requests should generally have no side effects. That is to say, it only obtains the resource information, just like the database query, it will not modify, increase the data, and will not affect the state of the resource.
* Note: the meaning of security here only means non-modified information.
(2)。 Idempotent means that multiple requests to the same URL should return the same result.
Idempotent (idempotent, idempotence) is a mathematical or computer concept, which is common in abstract algebra.
There are several definitions of idempotent:
For a monocular operation, if an operation is performed several times for all the numbers in the range, the result is the same as that of one operation, then we call the operation idempotent. For example, the absolute value operation is an example. In the real set, there is abs (a) = abs (abs (a)).
For binocular operation, it is required that when the two values participating in the operation are equivalent, the operation is said to be idempotent if the result of the operation is equal to the two values participating in the operation. For example, the function that finds the maximum value of two numbers is idempotent in the set of real numbers, that is, max (xmeme x) = x.
However, in practical application, the above two rules are not so strict. Cite examples of other people's articles: for example, the front page of a news site is constantly updated. Although the second request returns a different batch of news, the operation is still considered secure and idempotent because it always returns the current news. Basically, if the goal is that when a user opens a link, he can be sure that the resource has not changed from his own point of view.
two。 According to the HTTP specification, POST represents a request that may modify resources on a variable server.
Continue to quote the above example: take the news website as an example, readers should use POST to express their own comments on the news, because the resources of the site have been different or modified after the comments have been submitted.
However, in practice, many people do not follow the HTTP specification, and there are many reasons for this problem, such as:
1. Many people want convenience and use GET when updating resources, because you have to go to FORM (form) to use POST, which will be a little more troublesome.
two。 The addition, deletion, modification and query of resources can actually be done through GET/POST, without the need for PUT and DELETE.
3. Another is that the early Web MVC framework designers did not consciously treat and design URL as an abstract resource, so a serious problem is that the traditional Web MVC framework basically only supports GET and POST HTTP methods, but does not support PUT and DELETE methods.
* about MVC:
MVC originally exists in the Desktop program. M refers to the data model, V refers to the user interface, and C is the controller. The purpose of using MVC is to separate the implementation code of M and V so that the same program can use different representations.
The above three points typically describe the old style (not strictly following the HTTP specification). With the development of the architecture, there is now REST (RepresentationalState Transfer), a new style that supports the HTTP specification, which is not said here, but can be referred to "RESTful Web Services".
Then take a look at the difference between GET and POST from the surface:
(1)。 The first is that "data submitted by GET can only be 1024 bytes at most", because GET submits data through URL, so the amount of data that can be submitted by GET is directly related to the length of URL. In fact, URL does not have the problem of upper limit of parameters, and HTTP protocol specification does not limit the length of URL. This restriction is limited by specific browsers and servers. IE limits the length of URL to 2083 bytes (2K+35). For other browsers, such as Netscape, FireFox, etc., there is theoretically no length limit, which depends on the support of the operating system. Note that this is limited to the entire URL length, not just the data length of your parameter values.
(2)。 Theoretically, there is no size limit for POST, and there is no size limit for HTTP protocol specifications. It is inaccurate to say that "the amount of POST data is limited by the size of 80K/100K". There is no limit to POST data, and it is the processing power of the server's processor that limits it.
For ASP programs, there is a 100K data length limit for each form field processed by the Request object. However, there is no such restriction if you use Request.BinaryRead.
From this extension, Microsoft has increased the restrictions on IIS 6.0for security reasons.
We also need to pay attention to:
1). IIS 6.0 defaults that the maximum amount of ASP POST data is 200KB, and the limit for each form field is 100KB.
2). By default, the maximum size of uploaded files in IIS 6.0is 4MB.
3). The default maximum request header for IIS 6.0is 16KB.
There were no such restrictions prior to IIS 6. 0.
So the above 80K IIS5 100K is probably just the default value (note: I haven't confirmed the parameters for IIS5 and 80K), but I'm sure you can set it yourself. Since each version of IIS has different default values for these parameters, please refer to the relevant IIS configuration documentation for details.
3. In ASP, the server uses Request.QueryString to get GET request parameters and Request.Form to get POST request parameters.
In JSP, use request.getParameter (\ "XXXX\") to get, although there is also a request.getQueryString () method in jsp, but it is troublesome to use, for example: pass a test.jsp?name=hyddd&password=hyddd, use request.getQueryString () to get: name=hyddd&password=hyddd. In PHP, you can use $_ GET and $_ POST to get the data in GET and POST, respectively, while $_ REQUEST can get the data in GET and POST requests. It is worth noting that there are hidden dangers in using request in JSP and $_ REQUEST in PHP. Write a summary of this next time.
4.POST is more secure than GET.
Note: the security mentioned here is not the same concept as the "security" mentioned by GET above. The meaning of "security" above simply means no data modification, while here security means the real meaning of Security. For example, if you submit data through GET, the user name and password will appear in clear text on URL, because (1) the login page may be cached by the browser, (2) other people can check the history of the browser, so that others can get your account number and password. Submitting data using GET can also cause Cross-site request forgery attacks.
To sum up, Get is a request to the server for data, while Post is a request to submit data to the server. In FORM (form), method defaults to "GET". In essence, GET and POST have different sending mechanisms, not one to pick up and one to send!
This is the answer to the question on how to solve the inconsistent value of Ajax accessing session and the difference between GET and POST in HTTP protocol. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.