0

Not sure if this is a bug or I am missing something, most likely latter. My AFHTTPClient's base url is:

#define kBaseURL @"http://localhost:4567/api/"
self.client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:kBaseURL]];

When I make a request to, for example '/games', it actually sends the request to http://localhost:4567/games ignoring the API part.

0xSina
  • 20,973
  • 34
  • 136
  • 253
  • 1
    The answer to "Is this a compiler/OS/library bug?" is always "No, it's your code." –  Feb 07 '13 at 20:17
  • @H2CO3...i know what you are saying, but always? There's a reason why we have this https://developer.apple.com/bugreporter/ :) – 0xSina Feb 07 '13 at 23:28
  • @H2CO3 Really? http://stackoverflow.com/questions/14909324/nsjsonserialization-bug – 0xSina Feb 16 '13 at 13:06

2 Answers2

2

The "baseURL" part of "initWithBaseURL:" bit should make it clear that it's only going to work with the scheme + host + port number part.

Once you've created your client, you can add parameters onto it's URL request via techniques like:

NSMutableURLRequest *request = 
    [self.client requestWithMethod:@"POST" path:@"/api/games" parameters:parameters];
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • I think it would be easier to simply define base url as #define kBaseURL @"http://localhost:4567/api" without the last slash – Eugene Feb 07 '13 at 20:29
1

The AFHTTPClient.h file has tons of comments about exactly how to use /s to make sure everything fits together correctly. Check it out on github

Keith Smiley
  • 61,481
  • 12
  • 97
  • 110