我試圖使一個應用程序連接到OAUth 1的Web服務,我遇到了一些麻煩。這裏是我的方法和我的GET請求:AFNetworking獲取請求,獲取NSURLErrorDomain代碼= -1005
- (void)loadUserProfile
{
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[baseUrl]];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:[NSString stringWithFormat:@"/1/user/%@/profile.json", [SSKeychain passwordForService:@"[service]" account:@"encoded_user_id"]]
parameters:nil];
NSString *postString = [NSString stringWithFormat:@"oauth_consumer_key=%@&oauth_token=%@&oauth_nonce=%@&oauth_signature_method=%@&oauth_timestamp=%@&oauth_version=%@", self.auth.consumerKey, [SSKeychain passwordForService:@"[service]" account:@"oauth_token"], self.auth.nonce, self.auth.signatureMethod, self.auth.timestamp, self.auth.version];
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
}
當我把這個方法我收到以下錯誤:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0x8efa7f0 {NSErrorFailingURLStringKey=https://api.fitbit.com/1/user/[id]/profile.json, NSErrorFailingURLKey=https://api.fitbit.com/1/user/[id]/profile.json, NSLocalizedDescription=The network connection was lost., NSUnderlyingError=0x8bdb2c0 "The network connection was lost."}
我以前沒有用過OAuth 1
,之前我從來沒有見過這個錯誤,所以我不確定如何解決它。有任何想法嗎?
你有把握嗎?我試圖讓一個'我的HttpClient變量的strong'財產,我也得到了同樣的錯誤。強大的性能不應該得到釋放,對不對? – Anders
試圖使singelton的建議,有點無法得到它的工作。 – Anders