2011-07-11 13 views
0

可能性の重複:
Testing use of NSURLConnection with HTTP response error statusesどうすればconnectionDidFinishLoading:サーバー上にファイルが見つからない場合に実行できますか?

これは奇妙です。

​​

のNSLogが最後のファイルがサーバー上にない場合でも、実行されています。そして、私は、標準的なデリゲートメソッドの束を持っている

NSString *url=[NSString stringWithFormat:@"http://www.whatever.com/file"]; 

NSURL *url2=[NSURL URLWithString:url]; 
NSURLRequest *req=[[NSURLRequest alloc] initWithURL:url2]; 
NSURLConnection*con=[[NSURLConnection alloc] initWithRequest:req delegate:self]; 
[req release]; 

if(con){ 
    NSMutableData *data=[[NSMutableData alloc] init]; 
    self.receivedData=data; 
    [data release]; 
} 
else { 
    UIAlertView*alert=[[UIAlertView alloc] initWithTitle:@"Error!" message:@"Unable to connect to server." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 

:私はそうのような非同期接続を持っています。どうして?私はそれが何かをロードしているとは思っていませんでしたが、代わりにエラーと警告の表示になりました。

これらのメソッドは最初は明らかですが、ここでは、非同期接続が得られていないことがあります。

+1

[この質問を確認](http://stackoverflow.com/questions/697108/testing-use-of-nsurlconnection-with-http-response-error-statuses) – albertamg

答えて

2

DID仕上げローディング。それがHTTPエラーで終了したという事実は、その要点の横にある。

didReceiveResponseで取得したNSHTTPResponseオブジェクトには、404が入っている.responseCodeプロパティがあります。

関連する問題