Report abuse

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
#import <Foundation/Foundation.h>

int main (int argc, char const* argv[])
{
    NSAutoreleasePool* pool = [NSAutoreleasePool new];

    NSString* url = @"http://update.macromates.com/check";
    char const* fields = "type=nightly";

    NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[NSData dataWithBytes:fields length:strlen(fields)]];
    [request setValue:@"Test/1" forHTTPHeaderField:@"User-Agent"];

    NSError* error = nil;
    NSData* dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:&error];
    if(!dataReply || error)
        NSLog(@"error: %@", [error localizedDescription]);
    else if(id dict = [NSPropertyListSerialization propertyListFromData:dataReply mutabilityOption:NSPropertyListImmutable format:nil errorDescription:NULL])
        NSLog(@"reply: %@", dict);
    else
        NSLog(@"reply: %@", dataReply);

    [pool release];
    return 0;
}