我正在尝试以这种方式向 Dropbox 发布 HTTP 请求:
//NSString *urlString = [NSString stringWithFormat:@"https://api.dropbox.com/1/oauth/request_token"];
NSString *urlString = [NSString stringWithFormat:@"https://api.dropbox.com/1/delta"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
//set headers
[request addValue:@"OAuth oauth_version=\"1.0\"" forHTTPHeaderField: @"Authorization"];
//create the body
NSMutableData *postBody = [NSMutableData data];
//post
[request setHTTPBody:postBody];
//get response
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(@"Response: %@", result);
//here you get the response
}
响应应该是 JSON 字符串。
参数在这里:https ://www.dropbox.com/developers/core/api#delta
它提供了参数和版本,但我不知道如何设置它们。