2

次のようなcurlリクエストがあります

curl -H '承認: OAuth oauth_signature_method="PLAINTEXT",oauth_consumer_key="de4422f-f3ff-4929-bb65-eadc6f5218e2",oauth_token="85ab49a-9081-4641-812c-09d3130e3a8",oauth_signature="0723ba36-8d19-8d19- 9337-7e81004655c%26e385879b-0b57-481b-a8fc-8eb1426fc72"' 'https://external.ningapis.com/xn/rest/ippinn/1.0/User/?author=0n1s8aln92xhx&fields=iconUrl,email,url,fullName,birthdate 、性別'

NSURLRequest を使用して同じリクエストを作成したい 試してみて、フォーラムで検索すると多くの解決策が得られましたが、成功しませんでした

次のコードを実行しました

NSURL *url = [NSURL URLWithString:@"https://external.ningapis.com/xn/rest/ippinn/1.0/User/?author=0n1s8aln92xhr&fields=iconUrl,email,url,fullName,birthdate,gender"];  
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

[request setHTTPMethod:@"POST"];

NSString  *authorization = @"OAuth ";
authorization  = [authorization stringByAppendingFormat:@"oauth_signature_method=%@",@"PLAINTEXT"];
authorization  = [authorization stringByAppendingFormat:@"&oauth_consumer_key=%@",@"de4422f-f3ff-4929-bb65-eadc6f5218e2"];
authorization  = [authorization stringByAppendingFormat:@"&oauth_token=%@",@"85ab49a-9081-4641-812c-09d3130e3a8"];
authorization  = [authorization stringByAppendingFormat:@"&oauth_signature=%@",@"0723ba36-8d19-4fab-9337-7e81004655c%26e385879b-0b57-481b-a8fc-8eb1426fc72"];

NSLog(@"authorization =>%@",authorization);
[request setValue: authorization forHTTPHeaderField: @"Authorization"];

 self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (_connection) {
    self.receivedData = [[NSMutableData data] retain];
}

どこが間違っているのか教えてください

4

1 に答える 1

2
    NSURL *url = [NSURL URLWithString:@"https://external.ningapis.com/xn/rest/ippinn/1.0/User/?author=0n1s8aln92xhr&fields=iconUrl,email,url,fullName,birthdate,gender"];  
    NSString  *authorization = @"OAuth ";
    authorization  = [authorization stringByAppendingFormat:@"oauth_signature_method=%@",@"PLAINTEXT"];
    authorization  = [authorization stringByAppendingFormat:@"&oauth_consumer_key=%@",@"de4422f-f3ff-4929-bb65-eadc6f5218e2"];
    authorization  = [authorization stringByAppendingFormat:@"&oauth_token=%@",@"85ab49a-9081-4641-812c-09d3130e3a8"];
    authorization  = [authorization stringByAppendingFormat:@"&oauth_signature=%@",@"0723ba36-8d19-4fab-9337-7e81004655c%26e385879b-0b57-481b-a8fc-8eb1426fc72"];
    NSData *postData = [authorization dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
    NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
    [urlRequest setURL:url];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [urlRequest setValue:@"utf-8" forHTTPHeaderField:@"charset"];
    [urlRequest setHTTPBody:postData];
    [urlRequest setTimeoutInterval:60.0];

    NSURLConnection *tmpConn = [[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self] autorelease];
    self.connection = tmpConn;//I suppose "connection" is a retained property 
    if (_connection) {
        self.receivedData = [[NSMutableData data] retain];
    }
于 2012-07-23T13:05:44.843 に答える