gpt4 book ai didi

ios - 读取 NSURLresponse

转载 作者:技术小花猫 更新时间:2023-10-29 10:14:34 26 4
gpt4 key购买 nike

我正在向这个地址发送一个对象:https://sandbox.itunes.apple.com/verifyReceipt

NSUrlconnection我正在尝试使用此委托(delegate)方法阅读它:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response像这样:

NSlog(@"%@",response);我收到这段代码:

<NSHTTPURLResponse: 0x7d2c6c0>我需要以某种方式得到一个字符串。我该如何阅读?

最佳答案

我为另一个问题写了这个答案,但我认为它会对你有所帮助。看看具体的方法

-(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];
}

关于ios - 读取 NSURLresponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8036895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com