GET Login
- (void) GetLogin {NSString *urlstring = [NSString stringWithFormat:@ "http://localhost/login.php?username=%@&password=%@",Self. Username,Self. pwd];Nsurl *url = [Nsurl Urlwithstring:urlstring];nsurlrequest *request = [nsurlrequest RequestWithURL:url Cachepolicy:nsurlrequestreturncachedatadontload timeoutinterval:10.0]; //default is the GET method, no need to specifically specify nslog (@ "%@" , Requestnsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue MainQueue] completionhandler:^ (Nsurlresponse *response, nsdata *data, nserror *connectionerror) {id result = [nsjsonserialization jsonobjectwithdata:data options: 0 error:null]; nslog (@ "%@-%@", response, result);}];}
Basic format for URLs
- Logon script:
login.php
, hint: in different companies using the background interface is not the same jsp
, aspx
...
- If you want to take parameters, use the
?
join
- Parameter format:
参数名=值
- If there are multiple parameters, use the
&
connection
GET Cache
- The get cache data is saved in the cache directory under \bundleid
Cache.db
cfurl_cache_receiver_data
, all request data is cached
cfurl_cache_response
, all responses are cached
The above operation is only for demonstration, the content will be explained in follow-up SQLite
POST Login
- (void) Postlogin {Nsurl *url = [Nsurl URLWithString:@ "http://localhost/login.php"]; Nsmutableurlrequest *request = [Nsmutableurlrequest Requestwithurl:url]; Request. HttpMethod =@ "POsT";NSString *BODYSTR = [nsstring stringWithFormat:@ "username=%@&password=%@", self. Username, self. pwd]; Request. Httpbody = [Bodystr datausingencoding:nsutf8stringencoding]; [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue Mainqueue] completionHandler:^ ( Nsurlresponse *response, nsdata *data, nserror *connectionerror) { id result = [nsjsonserialization JSONObje Ctwithdata:data options:0 Error:NULL]; NSLog (@ "%@-%@", response, result);}];}
GET & POST Compare URLs
Request
Connection
- will be sent to the
请求
server
- Returns the binary data entity of the server
- Is the most simple method in network access.
GET
POST
No change, no matter how it is Connection
Comparison of Get and post