课堂演练准备项目001.网络基础_第1页
课堂演练准备项目001.网络基础_第2页
课堂演练准备项目001.网络基础_第3页
课堂演练准备项目001.网络基础_第4页
课堂演练准备项目001.网络基础_第5页
免费预览已结束,剩余18页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 oUd 2( * iOSZX!Q_, d w /liufan9 7): !#$%&$%( oUd 2( * ZXbC GET vsTCA snNH *+,T-./,*+,ls 0&1#&23450&3643 f2&%$#7(389:W ;o ML g =f s 7): !#$%&$%( oUd 2( * TLHTMLjERGET & 7): !#$%&$%( oUd 2( * iOSZX#G-HT?/89: 5 5?/89:9464$ -(NA42H3 s L?/89:=- 41A42H3g?/B6$&23489:9464$ v ?/89:9464$3vJ?/89:C7(4%$#7( o I

2、)kwY;TA42Hg3o ?/89:9464$=3s a|H3 7): !#$%&$%( oUd 2( * *+,bCBn URLNSString *urlStr = /login.?username=123&password=123;NSURL *url = NSURL URLWithString:urlStrstringByAddingPercentEscsUsingEncoding:NSUTF8StringEncoding; RequestNSURLRequest *request = NSURLRequest requestWithURL:url; ConnectionNSURLCo

3、nnection *conn = NSURLConnection allocinitWithRequest:request delegate:self; Connectionconn start; 7): !#$%&$%( oUd 2( * TbCBn / Connectiong NJ URLNSString *urlStr = /login.; RequestNSMutableURLRequest *request = NSMutableURLRequest requestWithURL:url;/ request setTimeouterval:5.0;/ request setHTTPM

4、ethod:t;NSString *bodyString = NSString stringWithFormat:username=%&password=%,_userNameText.text,_passwordText.text;/ NSData *body = bodyString dataUsingEncoding:NSUTF8StringEncoding;/ HTTPrequest setHTTPBody:body; 7): !#$%&$%( oUd 2( * -H%3=DNSURLConnectionDataDelega/-/HtBs(void)connection:didRece

5、iveResponse:2HB3s CA 7+- (void)connection:didReceiveData:/-/so (void)connectionDidFinishLoading:o.- (void)connection:didFailWithError:/ sNH T *CA- (void)connection:didSendBodyDa totalBytesExpectedToWrite:otalBytesWritten: 7): !#$%&$%( oUd 2( * TbCEV $lM WGET & 7): !#$%&$%( oUd 2( * GETbC8 P/ 8URLNSS

6、tring *urlStr = NSString stringWithFormat:%?username=%&password=%, LOGIN_URL, _userNameText.text, _passwordText.text;/ 3URL v NSURL *url = NSURL URLWithString:urlStrstringByAddingPercentEscsUsingEncoding:NSUTF8StringEncoding;/ 8NSURLRequest *request = NSURLRequest requestWithURL:url;/ 8oNSURLConnect

7、ion *conn = NSURLConnection allocinitWithRequest:request delegate:self;/ tDconn start; 7): !#$%&$%( oUd 2( * 0? ;5L $+ erface ViewController : UIViewController erface ViewController ()/ oBsCA 7+ 8# eo23sNSMutableData*_receivedData;-(IBAction)getLogin:(id)sender/ &Zos_receivedData = NSMutableDatadata

8、; 7): !#$%&$%( oUd 2( * feNSURLConnectionDataDelegate%3=D69;5/ 2HBs CA 7+- (void)connection:(NSURLConnection *)connection didReceiveData:(NSDataNSLog(2HBs%, data);_receivedData appendData:data;*)data/ sop- (void)connectionDidFinishLoading:(NSURLConnection *)connectionNSString *string = NSString allo

9、cinitWithData:_receivedData encoding:NSUTF8StringEncoding;NSLog(o B %, string);/ Es_receivedData = nil;/ o.- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError/ =URL3 cv. NSLog(o. %, error.localizedDescription);*)error 7): !#$%&$%( oUd 2( * TbC8 P/ &Zos_receivedData = NSMutable

10、Data data;/ 8URL b#3url NSURL *url = NSURL URLWithString:LOGIN_URL;/ 8NSMutableURLRequest *request = NSMutableURLRequest/ 41H3!grequestWithURL:url;request setTimeouterval:5.0;/ CA /Qrequest setHTTPMethod:t;NSString *bodyString = NSString stringWithFormat:?username=%&password=%,_userNameText.text, _p

11、asswordText.text;/ #s NSData *body = bodyString dataUsingEncoding:NSUTF8StringEncoding;/ HTTPs NSMutableURLRequest9fContent-Lengthrequest setHTTPBody:body;/ 8o 7): !#$%&$%( oUd 2( * NSURLConnectionDataDelegate%3=D/ sNH T*CA- (void)connection:(NSURLConnection *)connectiondidSendBodyData:(NSeger)bytes

12、Written totalBytesWritten:(NS(NSeger)totalBytesWritten totalBytesExpectedToWrite: eger)totalBytesExpectedToWriteNSLog(“sNH bytesWritten: %d,totalBytesWritten %d totalBytesExpectedToWrite bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);%d”,CAUOJ 7): !#$%&$%( oUd 2( * BbC .BbCNSURLConnecti

13、onPLrCAvo _ 7NSURLRequest ?S NSURLConnectionDataDelegates sendSynchronousRequest:request returningResponse:&response error:&error sendAsynchronousRequest:requestqueue:NSOperationQueue mainQueuecompletionHandler:(NSURLResponse NSData *data, NSError *error)Q $x$mq*response, 7): !#$%&$%( oUd 2( * B .Bb

14、CEV 7): !#$%&$%( oUd 2( * Ikc7): !#$%&$%( oUd 2( * BbCEVhAtbC=D 7): !#$%&$%( oUd 2( * hA L=D/ #T- (NSMutableURLRequest *)tLoginRequest/ 8URL b#3url NSURL *url = NSURL URLWithString:LOGIN_URL;/ 8NSMutableURLRequest *request = NSMutableURLRequest requestWithURL:url;/ 41H3!grequest setTimeouterval:5.0;

15、/ CA /Qrequest setHTTPMethod:t;NSString *bodyString = NSString stringWithFormat:username=%&password=%,_userNameText.text, _passwordText.text;/ #s NSData *body = bodyString dataUsingEncoding:NSUTF8StringEncoding;/ HTTPs NSMutableURLRequest9fContent-Length request setHTTPBody:body;return request; 7):

16、!#$%&$%( oUd 2( * BbCH1K/- (IBAction)syncLogin:(id)senderNSMutableURLRequest *request = self NSError *error;NSURLResponse *response;tLoginRequest;NSData *data = NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error;/ pW W JLOGIN_URLvu2Rif (!data) NSLog( D. %, error.

17、localizedDescription); else / qsNSString *string = NSString allocinitWithData:data encoding:NSUTF8StringEncoding;NSLog( B %, string); 7): !#$%&$%( oUd 2( * .BbCH1K/NSMutableURLRequest *request = selftLoginRequest;/ *y0 3 3 0 & error = nil) / qsNSString *string = NSString allocinitWithData:data encod

18、ing:NSUTF8StringEncoding;NSLog( B %, string);else if (data length 7): !#$%&$%( oUd 2( * Y&SJNSURLRequest3cachePolicyv- - F-333$Oz3Y $K3 Vl$!42H3s-| h=L613+cachePolicy%3- NSURLRequestUseProtocolCachePolicy 3- 3CA8-NSURLRequestReloadIgnoringCacheData NSURLRequestReturnCacheDataElseLoadX-,5-,5NSURLRequestReturnCacheDataDontLoad- R - koNSURLRequestReloadIgnoringLocalAndRemoteCacheData X 5T$3

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论