-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanHTTPModel.m
52 lines (42 loc) · 1.92 KB
/
ScanHTTPModel.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
//
// ScanHTTPModel.m
// Blue Canary
//
// Created by Crae Sosa on 10/25/13.
#import "ScanHTTPModel.h"
@implementation ScanHTTPModel
@synthesize responseData,delegate;
-(int) controlSetup:(int) s{
return 0;
}
-(void) serverConfirmation:(NSString *)uuidsToLoad{
self.responseData = [NSMutableData data];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[@"https://bluecanaryconnect.appspot.com/apphandle" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"ed" forHTTPHeaderField:@"NAME"];
[request setValue:@"ed" forHTTPHeaderField:@"PASSWORD"];
[request setValue:@"UUID" forHTTPHeaderField:@"COMMAND"];
[request setValue:uuidsToLoad forHTTPHeaderField:@"UUID"];
NSLog(uuidsToLoad);
//For testing
//[request setValue:@"7B72663A-7000-A511-F23C-9E2E5A2C7528,FC01C226-0EF5-8F59-75C6-1E3CCCFBCA01,12345" forHTTPHeaderField:@"UUID"];
(void)[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"didFailWithError");
//[self alert:NO];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *myError = nil;
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:self.responseData options:NSJSONReadingMutableLeaves error:&myError];
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
NSLog(response);
[[self delegate] scanHTTPconnectionDidFinishLoading:data];
}
@end