I saw your code and after looking at some other questions on this website, I finally create the executable code. In my case, I use AFHTTPClient to initiate the request, I just use OAMutableURLRequest to create the authorization header, then I use the authorization header to join the request that I send to the server.
I am sharing my code here for those who need it.
In your case, I think you should check sending the request to the server and use Fiddler to compose a test request to debug your service.
Sorry for my bad english: p.
NSDictionary * jsonDic; __block NSString *responsebody = @""; OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"123" secret:@"456"]; NSURL *url = [NSURL URLWithString:@"http://MyServiceURL/MyServiceFunction"]; OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:url consumer:consumer token:nil realm:nil signatureProvider:nil]; [request prepare]; NSString *oauthHeader = @"OAuth "; oauthHeader = [oauthHeader stringByAppendingFormat:@"oauth_consumer_key=\"%@\"",@"123"]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_token=\"%@\"",@""]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature_method=\"%@\"",@"HMAC-SHA1"]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_signature=\"%@\"",encodeToPercentEscapeString(request.signature)]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_timestamp=\"%ld\"", (time_t) [[NSDate date] timeIntervalSince1970]]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_nonce=\"%@\"",request.nonce]; oauthHeader = [oauthHeader stringByAppendingFormat:@",oauth_version=\"1.0\""]; //NSLog(@"oauthHeader: %@", oauthHeader); [AFNetworkActivityIndicatorManager sharedManager].enabled = YES; NSURL *baseURL = [NSURL URLWithString:@"http://MyServiceURL"]; AFHTTPClient* client = [[AFHTTPClient alloc] initWithBaseURL:baseURL]; [client setParameterEncoding:AFJSONParameterEncoding]; [client setDefaultHeader:@"Accept" value:RKMIMETypeJSON]; [client setDefaultHeader:@"Content-Type" value:@"application/json"]; [client setDefaultHeader:@"Authorization" value:oauthHeader]; NSDictionary *finalDict = @{@"user":@{@"id":@"001"}}; // create a JSON string from your NSDictionary NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:finalDict options:NSJSONWritingPrettyPrinted error:&error]; [client postPath:@"/MyServiceFunction" parameters:finalDict success:^(AFHTTPRequestOperation *operation, id JSON) { responsebody = operation.responseString; jsonDic = [NSJSONSerialization JSONObjectWithData:[responsebody dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableLeaves error:nil]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Hit error: %@", error); }];
and
NSString* encodeToPercentEscapeString(NSString *string) { return (NSString *) CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef) string, NULL, (CFStringRef) @"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8));}
source share