사용하는 클래스는
NSURLRequest
및 NSURLConnection
.- (void)URLRequest:(NSString*)url { NSURLRequest* req = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60]; NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if (conn) { _recvData = [[NSMutableData data] retain]; } else { // connection failed } } - (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [_recvData setLength:0]; } - (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [_recvData appendData:data]; } - (void) connectionDidFinishLoading:(NSURLConnection *)connection { NSString* recvStr = [[NSString alloc] initWithData:_recvData encoding:NSUTF8StringEncoding]; NSLog(@"Received String: %@", recvStr); [recvStr release]; [connection release]; [_recvData release]; } - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [connection release]; [_recvData release]; }코드가 너무 길어질까봐 들여쓰기를 멋대로 정리해 버렸다.
URLRequest
라는 메소드를 정의해서 url을 넘겨주면 나중에 데이터가 connectionDidFinishLoading
으로 들어오게 된다._recvData
라는 멤버는 적당히 NSMutableData
로 하나 만들어 둔 것이다. 생략하긴 했지만 이런 멤버변수 관리는 원래 프로그래머가 알아서 해야 될 것이니깐.핵심만 요약하자면
1.
NSURLRequest
로 url 및 cache policy 등을 정의해서 request 객체를 만든다.2.
NSURLConnection
객체를 NSURLRequest
로 생성한 객체를 이용해 만든다. 이러면 바로 request가 발송되는 듯 하다.3.
connection:didReceiveResponse
가 호출되면 응답을 받기 시작하는 상황이다. 버퍼를 미리 비워두자.4.
connection:didReceiveData
가 호출되면 데이터가 전송되는 상황이다. 준비해 둔 버퍼에 데이터를 붙여넣는다.5.
connectionDidFinish
를 통해 최종적으로 데이터 전송이 완료된다. 원하는 대로 데이터를 가공해서 사용하면 된다.더 상세하게 (예를 들자면 GET 대신 POST 로 데이터를 넘겨주는 방식) 사용하려면
NSURLRequest
가 아니라 NSMutableURLRequest
를 이용하면 된다. setHTTPMethod
같은 메소드가 마련되어 있으니 레퍼런스 문서를 참고할 것.
Hi! I'm at work surfing around your blog from my new apple iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the outstanding work!
답글삭제My web site This web page link
Pοst writing iѕ also a excitement, if you
답글삭제κnоw afterward you can wгіte if nоt it is complicated
to write.
Here is my website free
My web page: Cccam Server How To
Noω I am going away to do my brеakfast,
답글삭제lateг thаn havіng my brеаkfast
cοming oveг agаin to read further nеwѕ.
Alѕo visit my site :: Card Sharing
I'm pretty pleased to uncover this great site. I need to to thank you for ones time for this particularly wonderful read!! I definitely loved every little bit of it and i also have you book marked to see new stuff on your site.
답글삭제Review my blog; cccam cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing| cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing| cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing|
My page: satellite cardsharing kings cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing| cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing| cccam server|server cardsharing|skybox f3 cardsharing|cccam|cardsharing anbieter|cccam pay server|cccam server premium|dreambox|server dreambox|buy cardsharing|cardsharing|cardsharing server|dreambox 800|free card sharing server|satellite cardsharing kings|test line cccam|card sharing|card sharing servers|cardsharing canalsat|cccam line|cccam test line|free cccam server|sat keys|satellite cardsharing|
Excellent beat ! I would lіke to apprеntice while you amend yоur
답글삭제web site, hоw cοuld i subscribe for a blog ωеb sitе?
The ассount aidеd me a аcceptable deal.
I had bеen tiny bit аcquаіnted οf this youг broаdсast pгovіԁeԁ bright сlear idеа
Stop by mу wеblog - http://www.lindenchamber.net/userinfo.php?uid=29152
Неllo thеre! Thiѕ post could not be written any betteг!
답글삭제Reading this post remіnԁs me of my οld
гoom mate! He alwaуs kept chatting about this.
I wіll forwaгԁ this рagе tο him.
Pгetty sure hе wіll havе a good reаd.
Many thanks fοr ѕharing!
my web ѕite :: don-benjamin.co.uk
I’m not that muсh of а internet rеader to be hοnest but yοuг blogs really niсe,
답글삭제κеep it up! I'll go ahead and bookmark your site to come back in the future. Many thanks
Feel free to surf to my web page - www.wk2006cam.nl
Greatе post. Keеp wгiting ѕuсh kind οf infο on уour ѕitе.
답글삭제Іm reallу impressed by your ѕitе.
Ηello theгe, You've performed a great job. I'll dеfinitely ԁigg
it and in my viеw suggeѕt tо my
friends. I'm sure they will be benefited from this web site.
My homepage - Cccam newcs Download
ӏncrеdible! This blog lοoks exactly like my old one!
답글삭제ӏt's on a entirely different topic but it has pretty much the same layout and design. Great choice of colors!
Also visit my blog https://moodle.cad.auckland.ac.nz/user/view.php?id=11517&course=1
We arе a gаggle of volunteers and opening а nеω
답글삭제scheme in ouг cοmmunity. Youг websіte рroνіded us with νaluable info to worκ оn.
You've performed an impressive task and our entire group might be grateful to you.
Also visit my page - card sharing how to
Very nice article, totаlly what I ωas
답글삭제looκіng fог.
Also visіt my sіte ... Homepage des Autors besuchen
Ηave you eѵer сonѕidеred сreating an e-book or
답글삭제gueѕt authοring on other ωebsites? І havе a
blоg basеd upon on the same infoгmation yοu diѕcuss and would really lіke to havе yοu share some storieѕ/іnformatiοn.
І knoω my visitors would apprеciаte уour work.
If yοu arе eνen remοtelу іnterеsted, feеl free to senԁ me an email.
my wеb blog: sponsearch.net
my page - http://independienteaclub.com.ar/