0
我有以下代碼以獲得來自微博API twitter的ID和名稱:目標C GET方法的工作通過Wi-Fi,但不通過蜂窩網絡
{
NSString *StringUrl = [NSString stringWithFormat:@"https://api.twitter.com/1/users/show.json?screen_name=%@",account.username];
@try {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval: 15];
[request setURL:[NSURL URLWithString:StringUrl]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
if([responseCode statusCode] != 200){
NSLog(@"Error getting %@, HTTP status code %i", StringUrl, [responseCode statusCode]);
}else{
NSLog(@"Good");
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSString *twitterId = [json objectForKey:@"id_str"];
NSString *twitterName = [json objectForKey:@"name"];
}
}
@catch (NSException *exception) {
NSLog(@"No conection: %@",exception.name);
}
}
它工作正常通過WiFi網絡進行測試時;然而通過蜂窩網絡它迴應:
Error getting https://api.twitter.com/1/users/show.json?screen_name=enf_4eva, HTTP status code 400
在此先感謝。