我有一个如下网址:
http://www.test.co.uk/Requests.php?accessToken=01XJSK
根据访问令牌是否有效,返回 1 或“invalidAT”。但是,当我尝试返回该值时,我最终返回的是 HTML 而不是字符串。
这是我目前正在尝试的:
- (NSString *) getDataFrom:(NSString *)url{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:url]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
if([responseCode statusCode] != 200){
NSLog(@"Error getting %@, HTTP status code %i", url, [responseCode statusCode]);
return nil;
}
return [[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding];
}
谁能解释我如何返回“1”或“invalidAT”?