尝试将数据发送到CouchDB数据库时出错

时间:2015-06-04 05:57:12

标签: objective-c json couchdb

当我尝试运行此代码将数据发送到CouchDB数据库时,我收到错误:

  

2015-06-04 15:30:43.426 ddd [8303:640525] requestReply:{“error”:“bad_request”,“reason”:“需要引用标头。”}

无论如何我可以解决这个问题吗?

- (IBAction)sendDataToJson:(id)sender

{
    NSString *post = [NSString stringWithFormat:@"--"];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:@"http://127.0.0.1:5984/sgram/cc362033a500f51767fbc87efc0003ae"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];

    NSURLResponse *requestResponse;
    NSData *requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];

    NSString *requestReply = [[NSString alloc] initWithBytes:[requestHandler bytes] length:[requestHandler length] encoding:NSASCIIStringEncoding];
    NSLog(@"requestReply: %@", requestReply);

}

1 个答案:

答案 0 :(得分:2)

使用动词PUT代替POST