1

I am able to hit my API url with the following code and receive json data, However I need to specify what data to request with the following paramaters and values. How can I do this?

Paramater: q value: Chase

Paramater: page value: 1

NSMutableURLRequest *request3 = [[NSMutableURLRequest alloc] init];
[request3 setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request3 setURL:[NSURL URLWithString:@"https://MYWEBSITE.com/api/v1/intuit/institutions"]];
[request3 setHTTPMethod:@"GET"];
NSURLResponse *requestResponse3;
NSData *requestHandler3 = [NSURLConnection sendSynchronousRequest:request3 returningResponse:&requestResponse3 error:nil];
NSError *err3;
NSMutableDictionary *json3 = [NSJSONSerialization JSONObjectWithData:requestHandler3 options:kNilOptions error:&err3];
NSLog(@"%@", json3);
Trianna Brannon
  • 1,246
  • 11
  • 12
  • Possible duplicate of http://stackoverflow.com/questions/10087798/how-to-send-json-request-to-service-with-parameters-in-objective-c – Panama Jack Jan 29 '15 at 20:36
  • Take a look at this : http://stackoverflow.com/questions/9404104/simple-objective-c-get-request – Whirlwind Jan 29 '15 at 20:36
  • Unrelated, but generally an asynchronous method (such as `sendAsynchronousRequest` or any of the `NSURLSession` methods) is preferable to `sendSynchronousRequest`. – Rob Jan 29 '15 at 20:45

1 Answers1

1

Just figured it out, All the code is the same you just have to change the url address by adding the following to the end of the url ?paramater=value&paramater=value

NSMutableURLRequest *request3 = [[NSMutableURLRequest alloc] init];
[request3 setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request3 setURL:[NSURL URLWithString:@"https://MYWEBSITE.com/api/v1/intuit/institutions?q=chase&page=2"]];
[request3 setHTTPMethod:@"GET"];
NSURLResponse *requestResponse3;
NSData *requestHandler3 = [NSURLConnection sendSynchronousRequest:request3 returningResponse:&requestResponse3 error:nil];
NSError *err3;
NSMutableDictionary *json3 = [NSJSONSerialization JSONObjectWithData:requestHandler3 options:kNilOptions error:&err3];
NSLog(@"%@", json3);
Trianna Brannon
  • 1,246
  • 11
  • 12
  • That's fine, but the `Content-Type` is not `application/json`, so you should not set that header. Perhaps set `Accept` to `application/json` if you want, but not `Content-Type` – Rob Jan 29 '15 at 20:41