-3
如何從NSURLConnection獲取會話ID?如何從NSURLConnection獲取會話ID - IOS SDK
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
謝謝。
如何從NSURLConnection獲取會話ID?如何從NSURLConnection獲取會話ID - IOS SDK
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
謝謝。
NSURLConnection的使用代表獲得會話ID,如果您的請求得到反饋,會話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];
}
你要設定的協議NSURLConnectionDataDelegate,NSURLConnectionDelegate在.h文件中
你所說的會話ID的意思是?你有什麼嘗試? –
使用網絡服務,我們可以創建一些會話併爲登錄服務提供一些會話ID。如果我使用NSURLConnection連接某個API,則會創建一些會話。 IOS可以捕獲會話ID嗎? – user831098