-
Notifications
You must be signed in to change notification settings - Fork 1
/
DKURLConnection.m
55 lines (44 loc) · 1.43 KB
/
DKURLConnection.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// DKURLConnection.m
// wppost
//
// Created by Jonathan Younger on 8/7/04.
// Copyright 2004 Daikini Software. All rights reserved.
//
#import "DKURLConnection.h"
@implementation DKURLConnection
- (NSData *)sendSynchronousRequest:(NSURLRequest *)request followRedirects:(BOOL)flag returningResponse:(NSURLResponse **)response error:(NSError **)error
{
followRedirects = flag;
connectionData = [[NSMutableData alloc] init];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
while(connectionDidFinishLoading == NO) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
*response = connectionResponse;
return [connectionData autorelease];
}
-(NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
if (followRedirects) {
return request;
} else {
return nil;
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//NSLog(@"received response: %@", [(NSHTTPURLResponse *)response allHeaderFields]);
connectionResponse = response;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//NSLog(@"received data");
[connectionData appendData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSLog(@"connectionDidFinishLoading");
connectionDidFinishLoading = YES;
}
@end