-3

NSURLConnection からセッション ID を取得するには?

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];

ありがとうございました。

4

1 に答える 1

0

リクエストがセッション ID としてフィードバックを取得する場合は、NSURLConnection のデリゲートを使用してセッション ID を取得します。

-(void)connection:(NSURLConnection *)connection didReceiveResponse:
    (NSURLResponse *)response
{
    // Discard all previously received data.
    [receivedData setLength:0];
}

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

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    // Connection succeeded in downloading the request.
    NSLog( @"Succeeded! Received %d bytes of data", [receivedData length] );

    // Convert received data into string.
    receivedString = [[NSString alloc] initWithData:receivedData 
        encoding:NSASCIIStringEncoding];
    //receivedString will have session id if request is appropriate
    NSLog( @"From connectionDidFinishLoading: %@", receivedString );

    // release the connection, and the data object
    [conn release];
    [receivedData release];
}

.h ファイルに Protocol NSURLConnectionDataDelegate,NSURLConnectionDelegate を設定する必要があります

于 2012-09-28T06:56:44.260 に答える