I want to make a POST request on objective c using NSURL. I've communicated to the desired website with coding like this, however it is only for text.
NSDictionary *parameters = @{
@"data": text.text,
};
NSMutableString *parameterString = [NSMutableString string];
for (NSString *key in [parameters allKeys]) {
if ([parameterString length]) {
[parameterString appendString:@"&"];
}
[parameterString appendFormat:@"%@=%@", key, parameters[key]];
}
NSURLSession *session = [NSURLSession sharedSession];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://~~~"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[parameterString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
if ([data length]) {
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
//[liberal setText:[NSString stringWithFormat:@"%@", @"results"]];
NSLog(@"A: %@", jsonResponse[@"results"][@"A"]);
} else {
NSLog(@"%@", error);
}
}];
[task resume];
}
However, I was wondering if there was a similar method I could use for posting an image following these lines?
Basically I need to upload an image and retrieve a number from it. (after it has been analysed)