在我的应用程序中,我需要下载并发布一些数据......首先我需要下载一些数据,然后我需要做一个发布请求。我使用异步请求来不冻结我的应用程序的用户界面......但是当我调用我的方法来发布一些数据时......我不关心从服务器返回的数据。但是当我做一些发布请求时也会调用这个方法。
- (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;
}