2009-04-01 24 views

答えて

9

ここに行く!

この1人は、ウェブサーバーから画像を取得します。または、この1つは、Webページをつかむ

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"を設定して2番目の例を示します。 それから: NSData * responseData = [request HTTPBody]; と応答データが0バイトの情報で戻ってきます。 何か間違っていますか?私は応答を取得し、文字列に変換したい – Atma

2

NSURLConnectionをご覧ください。 URLを同期的または(好ましくは)非同期的に要求するために使用します。

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

しかし、あなたが本当に、おそらく欲しいのです::URLシステムの完全なマニュアルはこちらです

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

Appleはあなたが始める必要があるいくつかのサンプルコードを提供します。

関連する問題