2009-04-01 3 views

답변

9

여기 있습니다.

이 사람은 웹 서버에서 이미지를 가져옵니다. 또는,이 웹 페이지를 잡고

NSURL *url = [ NSURL URLWithString: [ NSString stringWithFormat:@"http://www.somewebsite.com/demo.png"] ]; 
    image = [ [ UIImage alloc ] initWithData: [ NSData dataWithContentsOfURL: url ] ]; 

...

NSURL *url = [ NSURL URLWithString:[ NSString stringWithFormat: @"http://www.google.com/search?q=%@", query ] ]; 
    NSURLRequest *request = [ NSURLRequest requestWithURL: url ]; 

는 비동기 작업을 수행하려면 NSURLConnection을 확인해야합니다.

+0

@ "joe"로 쿼리 변수를 채우는 두 번째 예제를 수행합니다. 그렇다면 다음을 수행하십시오. NSData * responseData = [request HTTPBody]; 이고 응답 데이터가 0 바이트의 정보로 돌아옵니다. 내가 잘못 했나요? 나는 응답을 얻고 문자열로 변환하고 싶다. – Atma

2

NSURLConnection을 살펴보십시오. URL을 동 기적으로 또는 (비동기 적으로) 요청하는 데이 URL을 사용합니다. URL에 시스템에 대한 전체 설명서는 여기에 있습니다 :

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html

는하지만 당신이 정말로 아마 원하는 것은 :

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html#//apple_ref/doc/uid/20001836-BAJEAIEE

애플은 당신이 시작하는 할 몇 가지 샘플 코드를 제공합니다.

관련 문제