问题描述
我向此发送对象: https://sandbox.itunes.apple.com/verifyReceipt
NSUrlconnection
,我想用这个委托方法读取:
with NSUrlconnection
and i am trying to read it with this delegate method :
code> - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
这样:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
like this :
NSlog(@%@,response);
i得到此代码:
NSlog(@"%@",response);
i am getting this code :
< NSHTTPURLResponse:0x7d2c6c0>
i需要得到一个字符串。
我如何阅读它?
<NSHTTPURLResponse: 0x7d2c6c0>
i need to get a string somehow.how can i read it?
推荐答案
我写这个答案另一个问题,但我认为它会帮助你。特别是看看方法
I wrote this answer to another question, but I think it will help you. Have a look in particular at the methods
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
和
- (void)connectionDidFinishLoading:(NSURLConnection * )connection
-(void) requestPage
{
NSString *urlString = @"http://the.page.you.want.com";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0f];
responseData = [[NSMutableData alloc] init];
connection = [[NSURLConnection connectionWithRequest:request delegate:self] retain];
delegate = target;
}
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if ([response isKindOfClass:[NSHTTPURLResponse class]])
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response;
//If you need the response, you can use it here
}
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[responseData release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
if (connection == adCheckConnection)
{
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//You've got all the data now
//Do something with your response string
[responseString release];
}
[responseData release];
[connection release];
}
这篇关于阅读NSURLresponse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!