HTTP を使用してサーバーに接続し、サーバーに文字列を送信して、サーバーから応答文字列を受信したいと考えています。URLでサーバーに接続し、サーバーからメッセージを送受信する方法についてのアイデアはありますか?
1575 次
3 に答える
4
All-Seeing Interactiveの優れたASIHTTPRequestソースを使用することをお勧めします:http://allseeing-i.com/ASIHTTPRequest。私はこれを行っています。リリースされたiPhoneアプリもいくつかあるので、コードがかなりしっかりしていることを確認できます。
これはCFNetworkAPIのラッパーであり、Webサーバーとの通信の面倒な側面のいくつかを容易にします。これはObjective-Cで記述されており、MacOSXとiPhoneの両方のアプリケーションで動作します。
これは、基本的なHTTP要求を実行し、RESTベースのサービス(GET / POST / PUT / DELETE)と対話するのに適しています。ASIFormDataRequestサブクラスを使用すると、multipart/form-dataを使用してPOSTデータとファイルを簡単に送信できます。
于 2009-02-26T13:53:19.363 に答える
4
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData that will hold
// the received data
// receivedData is declared as a method instance elsewhere
receivedData=[[NSMutableData data] retain];
} else {
// inform the user that the download could not be made
}
于 2009-02-26T10:21:09.513 に答える
1
NSMutableURLRequest
およびNSURLConnection
クラスを使用して、サーバーに接続し、文字列を送信し、応答を受信できます。開始するのに適した場所は、 URL ローディング システムの紹介 です。
于 2009-02-26T10:17:45.840 に答える