当前位置:网站首页>2. Common request methods

2. Common request methods

2022-07-05 02:45:00 _ Language and ink

The request method is the first word in the request line , It describes to the server the type of action that the client requests . stay HTTP Agreement , Different request methods just contain different semantics , But some conventional behaviors of the server and browser make a concrete difference between them
 Insert picture description here
In practice , The client and server have gradually formed a consensus , There are some common request methods stipulated by convention :

  • GET, Means to obtain resources from the server . The business data is in the request line , No request body
  • POST, Means to submit information to the server , Usually used to generate new data , Such as registration . The business data is in the request body
  • PUT, Indicates that you want to modify the data of the server , Usually used to modify . The business data is in the request body
  • DELETE, Indicates that you want to delete the data of the server . The business data is in the request line , No request body .
  • OPTIONS, Occurs in a cross domain pre check request , Indicates that the client applies to the server for cross domain submission
  • TRACE, Echo requests received by server , It is mainly used for testing and diagnosis
  • CONNECT, Used to establish the connection pipe , Usually used in proxy scenarios , Rarely used in web pages

GET and POST The difference between

Due to the conventional rules of browsers and servers , It's caused GET and POST Request in web The difference between :
1. Browser sending GET When asked , No request body is attached
2.GEt The amount of information requested is limited , Suitable for transferring a small amount of data ;POST There is no limit to the amount of information requested , It's suitable for transferring a lot of data .
3.GET The request can only be passed ASCII data , Encounter non ASCII The data needs to be encoded ;POST There is no limit to the request .
4. Most of the GET The data requested to be passed is attached to path Parameters in , It can reproduce the page completely by sharing the address , But it also exposes the data , If there is sensitive data transmission , Should not be used GET request , At least not in path in .
5. When refreshing the page , If the current page is through POST Requested , The browser will prompt the user whether to resubmit . if GET The requested page does not prompt .
6.GET The requested address can be saved as a bookmark ,POST Can not be .

Interview questions

1.http What are the common request methods ?

  • GET, Means to obtain resources from the server
  • POST, Means to submit information to the server , Usually used to generate new data , Such as registration
  • PUT, Indicates that you want to modify the data of the server , Usually used to modify
  • DELETE, Indicates that you want to delete the data of the server
  • OPTIONS, Occurs in a cross domain pre check request , Indicates that the client applies to the server for cross domain submission
  • TRACE, Echo requests received by server , It is mainly used for testing and diagnosis
  • CONNECT, Used to establish the connection pipe , Usually used in proxy scenarios , Rarely used in web pages

2.GET and POST The difference between

from http From the point of view of the agreement ,GET and POST They are just the first word in the request line , Except for semantic differences , In fact, there is no essential difference .
The reason why there are various differences in actual development , This is mainly caused by the default behavior of the browser .

Affected by the browser , In actual development ,GET and POST There are the following differences :
1. Browser sending GET When asked , No request body is attached
2.GET The amount of information requested is limited , Suitable for transferring a small amount of data ;POST There is no limit to the amount of information requested , It's suitable for transferring a lot of data .
3.GET The request can only be passed ASCII data , Encounter non ASCII The data needs to be encoded ;POST There is no limit to the request
4. Most of the GET The data requested to be passed is attached to path Parameters in , It can reproduce the page completely by sharing the address , But it also exposes the data , If there is sensitive data transmission , Should not be used GET request , At least not in path in
5. When refreshing the page , If the current page is through POST Requested , The browser will prompt the user whether to resubmit . if GET The requested page does not prompt .
6.GET The requested address can be saved as a browser bookmark ,POST Can not be

原网站

版权声明
本文为[_ Language and ink]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050240461999.html