A NSURLConnection wrapper for humans
- 600 lines of Objective-C you can understand
- runs on iOS 4+ and Mac OS X 10.6+
- just drag-and-drop .h and .m in your project
- new BSD license
- synchronous and asynchronous (block based) calls
- easy to set request headers, cookies and POST data
- easy to get response status, headers and encoding
- file upload with progress block
- HTTP and proxy authentication
You can fill a queue with fake responses to be consumed by requests started from unit tests.
STHTTPRequest *r = [STHTTPRequest requestWithURLString:@"http://google.com"];
r.completionBlock = ^(NSDictionary *headers, NSString *body) {
// ...
};
r.errorBlock = ^(NSError *error) {
// ...
};
[r startAsynchronous];
NSError *error = nil;
NSString *body = [r startSynchronousWithError:&error];
NSInteger status = r.responseStatus;
NSDictionary *headers = r.responseHeaders;
NSString *encoding = r.responseStringEncodingName;
NSData *data = r.responseData;
[r addHeaderWithName:@"test" value:@"1234"];
[r addCookieWithName:@"test" value:@"1234"];
r.POSTDictionary = [NSDictionary dictionaryWithObject:@"1234" forKey:@"test"];
[r setUsername:@"test" password:@"1234"];
[r setProxyUsername:@"test" password:@"1234"];
[r setFileToUpload:@"/tmp/photo.jpg" parameterName:@"photo"];