を送信することですあなたはユーザーとパスワードのAPI
// Create the request
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:0];
// New Create the connection
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sharedSession];//sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
NSURLCredential *creds = [NSURLCredential credentialWithUser:self.username password:self.password persistence:NSURLCredentialPersistenceForSession];
NSString *authStr = [NSString stringWithFormat:@"%@:%@",self.username,self.password];// @"username:password";
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];
// Part Important
[request setValue:authValue forHTTPHeaderField:@"Authorization"];
// Or Token
NSString *authValueToken = @"OAuth UElJRFER1A5zcGkyW16T0";
[request setValue:authValueToken forHTTPHeaderField:@"AuthenticatedToken"];// Authenticated API
NSString *postLength = [NSString stringWithFormat:@"327"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
NSString *postLength = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
[request setValue:postLength forHTTPHeaderField:@"Content-Type"];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
receivedData = [NSMutableData data];
NSString* responseData = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(@"%@",responseData);
if (error) {
[self handleError: error];
}
}];
[dataTask resume]; // <- important
NSLog(@"Header Fields Request--->> %@",request.allHTTPHeaderFields);
Oauthデータをサーバーに送信するためにAuthorizationヘッダーを送信する必要があります。 –
@AdamCarter質問を更新して、これがOAuthに固有であることを含めてください。 – quellish