2011-12-07 14 views
0

今、私は応答のボディを取得したいと思います。私はIOS開発者の新しい人です。私はkownのみです。私はresponse.statusCodeを使用してhttpstatuscodeを取得できます(400,500など)。しかし、どのように応答の本文を取得する。たぶんallheaderFiledsまたはdataまたはerror.Description?あなたがNSURLConnectionのデリゲートであるオブジェクトが必要になりますURL Loading System Programming GuideIOSで応答本文を取得する方法は?

+0

どのようなAPIを使用してステータスコードを取得していますか? – ThomasW

+0

がdidReceiveResponseにあり、response.statusCode – user1084961

+0

Sthのように使用します: 'response.status_code == 200:data = xmltodict(response.content、[])'?それはPythonのです – Kjuly

答えて

1

詳細はでご利用いただけます。 receivedDataメンバー変数が必要です。デリゲートメソッドを実装する必要があります。

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    [receivedData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 
{ 
    // Append the new data to receivedData. 
    // receivedData is an instance variable declared elsewhere. 
    [receivedData appendData:data]; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    // do something with the data 

    // release the connection, and the data object 
    [connection release]; 
    [receivedData release]; 
} 
関連する問題