NSUrlConnectionDelegate - http ステータス コードの取得 質問する

NSUrlConnectionDelegate - http ステータス コードの取得 質問する

iOS では、Web サーバーからの応答の http ステータス コード (404、500、200 など) をどのように受信できますか。これは NSUrlConnectionDelegate にあると想定しています。

Objective-Cまたはモノタッチ.NET の回答は OK です。

ベストアンサー1

はい、デリゲートメソッド -didRecieveResponse でステータス コードを取得できます。

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
   NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
   int code = [httpResponse statusCode];
}

おすすめ記事