I have made this so far. It’s code that will make a json String request with an http Header. When i run this code i get no errors. But i get a Expression result unused warning. I should get a response from the web service after sending this http header.
code:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *nid = @"";
NSString *vocab = @"";
NSString *inturl = @"testoverview";
NSString *mail = @"chh@fbr.dk";
NSString *md5pw = @"4d57e7ef1b7c3f431aca424764e9d786";
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
nid, @"nid",
vocab, @"vocab",
inturl, @"inturl",
mail, @"mail",
md5pw, @"md5pw",nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDictionary options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
if (!jsonData) {
NSLog(@"Got an error; %@", error);
} else if(jsonData) {
NSString *url = @"http://www.taenk.dk/services/mobile";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLCacheStorageAllowed timeoutInterval:30.0];
[request setValue:jsonString forHTTPHeaderField:@"X-FBR-App"];
[[NSURLConnection alloc] initWithRequest:request delegate:self]; <-- this line triggers the warning: "Expression result unused"
NSLog(@"jsonString %@", jsonString);
}
Can anybody clarify 2 things for me:
- Does this trigger a response as soon as the request to the web service?
- If yes, how do i print this result out?
You need to assign the result to a variable like
for later use (e.g.
[con cancel];)Then you should at least implement the delegate method
connection:didFailWithError:. In the class reference I don’t see theconnection:didFinishLoading...anymore. Can you use thesendSynchronousRequest:returningResponse:error:instead, then you’ll have the result, be it positive or negative.This is how I retrieved the data (this version is without ARC):
msgcontains the pure response data, no header or such.