当我在 xcode 调试模式下研究这个方法时,在构造请求时会发生一些奇怪的事情。
- 额外的字符被添加到
urlString
. 例如if SessionId = "abc"
,然后在执行从 开始的行之后NSURLRequest *request...
,调试器会显示SessionUrlString = "...session/abc\x03" instead of simply "...session/abc"
. 尽管调试器仍然显示SessionId = "abc"
. 为什么是这样? 请求对象似乎不包含
url
任何地方,即使它的构造函数只是将它url
作为一个变量。它去哪儿了?它是否存储在对象某处的请求对象中AFHTTPCLient
?-(NSObject*)makeRequestForSessionUsingId: (NSString *)SessionId{ NSString *baseSessionURLString = [kCwAPIBaseURLString stringByAppendingString:@"session/"]; NSString *SessionURLString = [baseSessionURLString stringByAppendingString:SessionId]; NSURL *url = [NSURL URLWithString:SessionURLString]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; __block NSObject *sessionJSON = [[NSObject alloc] init]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"IP Address: %@", [JSON valueForKeyPath:@"origin"]); sessionJSON = JSON; } failure:nil]; [operation start]; return sessionJSON; }