gpt4 book ai didi

iphone - NSURLConnection 区分2个不同的请求

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:54:28 25 4
gpt4 key购买 nike

在我的应用程序中,我需要下载并发布一些数据...首先我需要下载一些数据然后我需要做一个发布请求。我使用异步请求不卡住我的应用程序的用户界面...但是当我调用我的方法来发布一些数据时......我不关心从服务器返回的数据。但是当我做一些发布请求时也会调用这个方法。

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)aResponse
{
NSLog(@"------------------------------- connectionDidReceiveResponse");
expectedResponseLength = [NSNumber numberWithFloat:[aResponse expectedContentLength]];
URLresponse = aResponse;
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{



[self.responseData appendData:data];
}

我如何在不调用(自动)这两种方法(向上)(在我下载信息时使用)并且不卡住用户 GUI(我在发布请求时不关心数据但是我在第一种情况下需要数据)?

我的发帖请求是这样的:

- (void)postRequestWithURLState:(NSString *)url
{
NSString *bodyRequest = nil;
NSURL *requestURL = [NSURL URLWithString:url];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] init];

//NSLog(@"-------------- bodyRequest: %@", bodyRequest);



[theRequest setURL:requestURL];
[theRequest setTimeoutInterval:2.0];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[bodyRequest dataUsingEncoding:NSASCIIStringEncoding]];
[self.oauthAuthentication authorizeRequest:theRequest];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:theRequest delegate:self];




self.web = conn;




}

最佳答案

我在网上四处寻找解决方案,最终我只是创建了自己的 NSURLConnection 子类并分配了一个标记变量来区分。看看这个blog post了解更多信息

关于iphone - NSURLConnection 区分2个不同的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401706/

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