There are two very important headers in the HTTP request, namely get and post. For Baidu this kind of server access, do not need to pass what parameters, convenient and quick access, mostly with get. When you need to enter your account password or pass information (images, etc.), the POST request is used.
(a) Get:
A GET request can be cached. The data entered when the GET request is displayed on the "url", usually? The following key values are appended to the parameter, and multiple parameters are connected by &. And the parameters generally do not have Chinese, if there is Chinese, you need to add percent escape. str = [STR stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; In the HTTP protocol, the length of get is not explicitly specified. However, depending on the browser, it is usually between 2-8k.
1- (void)Get{2 3NSString *str =@"Http://127.0.0.1/login.php?username=zhangsan&password=zhang";4 5str =[str stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];6 7Nsurl *url =[Nsurl Urlwithstring:str];8 9 TenNsurlrequest *request = [Nsurlrequest requestwithurl:url cachepolicy:1timeOutInterval:10.0]; One A[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) { - -Nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:data options:0Error:null]; the -NSLog (@"%@", dict); - - }]; + -}
(b) Post:
Post is much less efficient than get and cannot be cached to send some important data to the server. For example, to submit an encrypted account password or some other data. The size of the commit data follows the rules of the server. The parameters of the post are individually wrapped by a single request body. After being sent to the server, the server chooses the passed data according to the request body (the request body is binary data).
1- (void) post{2 3Nsurl *url = [Nsurl urlwithstring:@"http://127.0.0.1/login.php"];4 5Nsmutableurlrequest *request = [Nsmutableurlrequest requestwithurl:url cachepolicy:1timeOutInterval:10.0];6Request. HttpMethod =@"Post";7Request. Httpbody = [@"Username=zhangsan&password=zhang"datausingencoding:nsutf8stringencoding];8 9[Nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, NSData *data, Nserror *connectionerror) {Ten OneNsdictionary *dict = [nsjsonserialization jsonobjectwithdata:data options:0Error:null]; A -NSLog (@"%@", dict); - the }]; - -}
(c) Baidu makes a request:
After pasting the address, it was found to be like this--
Https://www.baidu.com/s?wd=%E6%88%91%E7%9A%84%20%E4%B8%96%E7%95%8C
This is because the Get method itself is ASC, and the Chinese is escaped. Where 20% is a special space escape character.
Then monitor this time Baidu's request.
In the response header--
This tyoe is the code and some rules to follow.
In the request header--
The user-agent displays the currently received device, number. If you change to a mobile phone, then Baidu is the display of M Baidu's mobile phone style.
(d) The server sends a POST request
You can see that parsing is JSON, encoding is UTF-8, the receiving device is Mac OS
And at this time there is a request body, the request body carries the data transmitted to the server side (this data is usually encrypted)
Parsing results can also be seen in JSON: (JSON corresponding key-value pairs)
Thus, the network data can usually be crawled to get some of the tail and back information, and then through the OC code to achieve.
Http:get&post method