到目前为止,我已经做到了。它将使用 http Header 发出 json String 请求的代码。当我运行此代码时,我没有收到任何错误。但我得到一个表达式结果未使用的警告。发送此 http 标头后,我应该从 Web 服务获得响应。
代码:
- (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);
}
任何人都可以为我澄清两件事:
- 这是否会在请求 Web 服务后立即触发响应?
- 如果是,我如何打印这个结果?